Big refactoring

working on AI