fix write bug