Add utility function wait_for_ok.
Rework with better security.