Refactored, moved logic into model