cmd_update_ref(): make logic more straightforward