v0.40 Optimization now runs with 2 loops