Refactored to support different database types and deployments