update write function