General tweaks to the AI; should resolve several bugs