use lastLine instead of lineCount

lastLine returns 1 less than lineCount so I also changed the check
to be less than, rather than less than or equal to