moving logic into model