Fix stream closing