fix eof issue, add test cases