Refactoring main controller