improving duplicateWrite