update write logic