Refactors database module, ready for Shapefile integration.