Added proper EOF handling.