Problem with creating modal window from collection item

I’m building a shopfront and have variants including images for some of my products. The variants are held in a collection (Beauty Variants) which is accessed as a multi reference field in my main products collection (Beauty Products). I want to be able to show larger versions of the variant images so have created a popup modal to show a larger version of the image on clicking the small image. The modal pops up OK, but the image shown is always the last one in the multi-ref field, rather than a larger view of the selected image.

Also the close modal button isn’t working on the published site although it works in Preview mode.

My read-only link is below. A typical page showing the incorrect behaviour is:

Any help would be much appreciated!