I found a logic bug in this double-loop.