Factor loader into a database storer and a batch loader

This section is my least favorite, so I'd appreciate feedback on how to restructure it.