refactored code for model