minor changes to handle end of file