Some cleanup and minor optimization.