Refactor logic into class