Updated the SwitchState function to actually work.