Fixed AI algorithm, refactored methods