improved union implementation