Refactor DB related classes