Fixed AI and threading