tweak to wait_for function