Added some comments and a little code cleanup.