updated ai state machine