Explain the "autoSwitch" function