towards implementing union

fixed several bugs
need to solve performance issues