refactor StringBuilder usage to a common implementation