Lots of documentation and cleanup