If you find the matching metadata, and all is OK, why continue?
I may have misunderstood something but ... a 'break' seems more accurate to me, to break the inner loop and start with the next metadata from iterator i1.

[ A break 'should' not break out from both loops, but this must be confirmed ]