factor the wait() and dont wait in non-interactive mode