General code cleanup and better documentation.