added write function