code cleanup and comments
more cleanup and comments