code cleanup and documentation

code cleanup and documentation