Query tests
Query test cases & small fixes