Update replace_domain function