Lots of changes, added more comments to clarify a few things, etc.