Extended the AI framework, some refactoring;