fixed bug for write