trying to refactor some controller logic into model