split out chunk processing into its own function
remove spurious newlines in log file