Adding a gsub line to remove extraneous newlines from output