Refactor some logic into a Controller