More work on AI state machine