How can I correctly access a figure caption that contains a counter?

I have a similar problem as I did a while back. I configured ref to show me the caption of a figure that contains a counter. However, it doesn’t show the counter number of that caption, but the final result of the counter. What do I need to change?

#let count = counter("nfr")
#let nfr(name, reference: none) = {
  count.step()
  [
    #figure(
      table(
        columns: (auto, 3fr),
        [*ID*], context count.display(),
        [*Name*], name
      ),
      caption: [NFR #context count.display(): #name]
    ) #if (reference != none) { label(reference) }
  ]
}

#nfr("Hello", reference: "hello")
#nfr("World", reference: "world")


#let nfr-reference(label) = {
  show ref: r => {
    if r.element == none { panic("Label '" + str(label) + "' not found") }
    let caption = r.element.caption.body
    link(label, caption)
  }
  ref(label)
}

Caption: #nfr-reference(<hello>). This should show NFR 1.

I found the solution: The problem was that the ref call accessed the #context count.display() again, thus accessing the value of the counter as it was at the position of that reference.

To fix it, simply move the function call outside the caption

#let nfr(name, reference: none) = {
  count.step()
  context {
    let current = count.display()
    [
      #figure(
        table(
          columns: (auto, 3fr),
          [*ID*], current,
          [*Name*], name
        ),
        caption: [NFR #current: #name]
      ) #if (reference != none) { label(reference) }
    ]
  }
}