Optimization and cleanup.