fix write bug and add limit option