code cleanup and comments