moved code from last commit to the controller.