Finished StateMachine, various bug fixes..