factor out do_rename