Cleanup and optimizations.