added EOF check to gettok function