Some code cleanup and documentation.