Move database-related code into dedicated module. Add a module for utility functions. Use newer namespaces in existing code.