modify querying to limit memory usage