Fix ports re-registering and re-unregistering