Cost Optimization Loop