Fixed bug #63. There may still be a race condition with the wait_for call, but
that one needs to be handled with a more general solution.