Fixed a bug in cleanup code for AIStateMachine.