Improved performance of string wrapping algorithm