refactoring for db