Refactoring for ai manager