fixing query bug