Added some commentary and cleaned up some code.