improved wait() function signature