Move code to MainController