Adding more waits to deal with unpredictable ci runners
Nicer wait infrastructure
Made waiting more general.