Fixed query logic.