refs: factor delete_ref loose ref step into a helper