halfway through refactoring
ai refactored