fix the bug to handle the eof cases