Refactored code for models.