Thanks, muraria - but I'm kicking myself for making it harder than it needed to be.
I realise now that I was predisposed to tackling it the way I did because I'd had a go at setting something similar, and that's how I did it (this was streets ahead of my effort}.