Added unexpected EOF check