Migrate some code to MainController