General code cleanup and comments