Fixed the write function.