Fix query formulation