Better use of `wait` in upgrade function