fixed query and added test cases

close #224