fix event handlers are not removed when they are no longer needed