length trim while error correcting