Some code cleanup and (tiny) performance optimizations.