`mode` can be moved out from this funtion without much trouble. But for `modeCompleted` and `modeInit`, since they are more or less coupled with the local states, moving them out would mean moving those relevant states out from the scope as well, and that might not be a good picture. I would suggest, put `mode` outside and let `modeCompleted` and `modeInit` stay inside.