Cleaning up query and query spec