Complete overhaul of AI, should work now.