move the code into the controller