Optimizations and cleanup.