Swap order of dialog show and add event listener to be more readable.