Refactor db class