refactoring code - adding logic to model