fixed bug in write