Cleanups and optimizations.