Fix bug in handling of eof