error with query construction