Made change to yashwitha's code. Dialogs are now cancelable.