write on close. Not complete