Fix broken captures on closures created in nested loops