Refactor DB operations into a separate type class