refactor db