ChatGPT has provided a few suggestions (ie example above) - which I can now go off try out. I've spent a lot of time digging through stack overflow and various tutorials trying to work this out and basically settled on a 'good enough' solution. Challenging that now with AI.