Added comments and cleaned it up a bit.