Correctly terminates on file end