refactor : reduced the number of times of the memory copy in the write() method.