Added registering and unregistering of listeners for portabillty.