Refactor MainController