Fixed iterating over events when clearing their handlers.