More escaping fixes and newline trimming