clone: factor out remote ref writing