Fun problem for the dev team.
I've started several different replies with what I thought were the "obvious" solutions, before seeing problems with them and starting over.