handle close correctly after detach