Replace textwrap module with custom code to improve performance.