refactor some methods with db work