fixed AI, added tests