fix bug "write is not defined"