mode code cleanup