added whenReady utility functio