Code cleanup and a bit of documentation.