move logic into model