Added changes suggested by Ken to get rid of the segfault on double (finally-induced) close()