I'm not totally clear on the flow here, but does this work with nested for loops?