Fixed bad merge regresion in checking of outgoing domain on removal

Also added rewriteDomain defnesive code