Continued refactoring the database module