Added some comments and cleaned it up a bit.