Refactoring of mode switching