More code cleanup and improved doc.