BGH,
Apologies, slapped that together all too quickly from a pre-existing system of mine and to put it simply, I screwed up...
I tend to dismiss insanely obvious approaches immediately and should have given this the more critical look it deserved.
Anyway, here's a clean write of your...