Clean-up and minor optimizations.