Fix loop in AI