Add better handling for newline at the end of the file