refactored code, added AI