Refactor of MainController.