fixed handling of eof