adding some logic to deal with unions