JavaScript dialog now handles clean-up on close