Refactored db class and entities