Removed unnecessary globals. Diagnosed AI issue.