Refactoring of the AI