fix data writing