Refactored logic out of helper into the model