Adding some comments and a little code cleanup.