Multiple EOF

* Fix two additional cases where multiple EOF handling was incorrect
* Add tests for multiple EOF handling (covers this change as well as #531)