Some bugs with the state machine implementation solved.