refactored code: implemented ActiveRecord ORM