Started Ai refactoring.