Improved fix for overlay window crashing when user clicks on it