Improved string normalization code.