fixes issue where close handler would be called twice