Changed the implementation of waitForDialogTo methods