I quickly tidied up the code a bit. Added some comments to make it
readable as I was messing around a fair bit with variable names etc.
Still a few ambigious ones, I apologize :P.