Added a few fixes in the state switching system