in reply to Until loop / unique
If so I'd consider a count of keys to drive the decision to dive any deeper. Carry the prefix with you as you recurse so you can assemble the full key path before returning it to the calling layer.