Refactor db