Refactor db package