added the write function