refactored logic out to model