simplification and bug fixes in the query system.