Second try to work around the stuck set problem while using "while held".

This version of the workaround works with more use cases than the
previous workaround. So far, it works the way that I would want it to
for the cases that I have tested. The code is a bit messy though.