possible crash fix when closing (#212)