Cleaned up some the code for loading large queries.