Fixed end state by testing for eof