Minory query bug fix and added test case