Restruct ai

Here is my work on making the AI code more readable.