fix close function