Minor optimizations to AI.