Added some missing EOF error messages, and cleaned the code a bit.