some code cleanup and documentation