Yet another batch of code cleanup and comments