Fix AttributeError on close