I have a whole article devoted to this problem, please read:
Wish You Were Here… Only Once[
^].
The technique I invented is quite sophisticated; in part, I planned this work as a kind of computer joke illustrating non-trivial things related to stack, uniqueness, etc. Nevertheless, this is practically well-working code. But I also describe the problem and its "usual" solutions.
—SA