Refactoring main switch.