Adding check for eof