Fix bugs for AI