improve stability of .write()