Fixed the state control bugs.
Updated