Refactored database connections