Cleanup just before removing the element