More code cleanup and comments