fix write exception