Refactored the AI logic.
Merge branch 'newStuff' into master