Code above should be probably use in write too so we have this same behavior when using write and writeFile