refactor the text width code