Fixing query error