Isolate common wait_end logic