Corrects the previous memory leak fix. We should not remove the shared callback function until all events are removed from the element.
Adds unit tests to try and verify #1005. Can't reproduce, closing for now.