write function implemented