removing dead code from queries
moving leak-check around