fix eof handling (closes #18)