VID-1082 Refactor some of the logic into the controller