fixed bug where union queries are not handled correctly