Fixed query creation