AI improvements.

Patch by: @St3eT
Reviewed by: @Zoey76