code cleanup and documentation