fix infinite loop in AI