fix a off-by-one bug in intersectWith(), and add a bunch of tests