Refactoring with mainController