Improve the length calculation.