Refactoring to make threaded and linear queriers share basic code