Consider adding an early exit from this function: `if (currentMode == mode) return;`