fix crash at closing