added support for union and intersection.
fixed bugs concering union and intersection