Lots of cleanup and documentation