Fixed some issues here and there related to event registering and unregistering.