Improved the waitForDialog methods