Lots of cleaning up and commenting.