mode code refactoring