Simplified a query to fix bug