Major changes to the query code.