refactoring db and related tests