fix bug when encountering EOF character