fix writing bug