Rework the way the matching metadata is created

Let's not loop just to find one key.

Change-Id: I4bf54f0039d971d167a99ac00b786497a1cbca64
Merge "Rework the way the matching metadata is created"