Optimization code (#10158)