cleaning up memory leaks by unregistering events