Fixing query def