Added docstring for replace_relations