Refactoring db access