Improved newline check code