fix bug when last line ends with spaces or blanks