Improve & simplify buffer newline trimming