fix query parsing and test cases