A quick pass at documentation. A bit of code cleanup.