Refactored database connection module.