fixed bug for query formulation