refactoring db layer