Made AI a bit smarter and fixed a couple bugs