Factored common newline-trimming code into its own proc.