ai refactor