fixed duplicate last-line error with eof check