Now the state machine seems to work...