Refactoring the way batches are run, to keep memory usage down.