Refactor mode to use the new helper functions.