Merged Ai code with rest of code