Lots of cleanup, AI improvements