made EOF handling more sensible