Added write function upon completion