refactoring for mode changing