Added error handling to controller.