Added some comments and tidied up some indentation.