Fixed bug in unregistering event