Reimplement set intersection

This can probably be done better, but this at least works.