restructuring some of the batch query internals, putting some unit tests around batch querying