Fix a bug preventing set operations from working as expected, and add a regression test.