(try to) fix exceptions when closing