Updated union logic to be much faster.