Fix replace() overriding original value of $$chain