Refactored to support multiple database connections in config