Improved the string width calculations.