refactored the string rendering part out into a separate function