db refactor