moved all logic into the controller for easier testing