handle close correctly