Better 'wait for' algorithm