Cleanup and optimization.