slight change to replace_refs