Refactor database connection pool handling