Refactored database and ORM code design