Adding AI and refactored tests