consolidate replace_keys func