Moved text string formatting into separate function