Add "destroy" event and rework code to use it