Fixing locationChange to check if dialog is open before calling close