More work on state machine