Refactor the AI