improve union performance
fix union function and add test for exception