Fix some various issues with mode toggling.