Cleanup for query