move condition check to after wait()