Fix the failing tests in the query construction