de-dupe writing function