write function