Code cleanup and documentation.