fixed bug in query formulation