fix write stream errors