fixed data writing bug