Fixed query bug