Added write function