Refactoring in AI module