bug fix in write