fixing query scoping