Move comment code to a separate function so it can be separately tested. Original patches by Todd Rovito and Phil Webster.