Refactored Code
Moved logic to model