modify algorithms for union and difference ops