Does unit['metadata'] have the unit_key fields in it? I only have vague recollections of this, but I thought there was a unit['unit_key'] attribute. If so, we could avoid this for loop constructing it. If not, well, my memory isn't always the most reliable.