Minor code cleanup and optimizations.