fix write corruption