First commit, code copied from http://pastebin.com/pnZjApsT
Added some comments on ownership (trivial)
Changed IF statement to now show 'final state reached' message
correctly.