Refactoring database factory