[SOLVED] Struggling with buttons in repeater

I’ve added a repeater to allow users to add guests. Inside each container is a delete button.
For some reason that I can’t figure out it’s running 3 times every time I click on delete regardless of how many entries are in the array. Can anyone see what I’m doing wrong?

export function deleteGuest_click(event) {
  $w('#addGuestTick' ).enable();
  let $item = $w.at(event.context);
  let guestId=+$item('#guestId').text;
  
  let x=guestId;
  console.log(guestId);
  for (let i = x; i < guestsData.length-1; i++) {
    guestsData[i].guestName = guestsData[i + 1].GuestName;
  }
  guestsData.pop();
  $w("#guests").data = guestsData;
  $w("#guests").forEachItem( ($item, itemData, index) => {
    $item("#guestName").text = itemData.guestName;
  } );
  if (guestsData.length==0) {
    $w("#guests").collapse();
  }

Not sure if I’ve fixed it or just come up with a workaround. I’d created the repeater using a blank repeater template which just happens to have 3 containers.
I’ve replaced it with a repeater I found in an example that had a single container. Which works! Yay for me!