fixed crash-on-close bug