Fix EOS handling bug