Added some comments and some code reformatting