Changed file reading to be more responsive to the end of the file being reached, removing some bugs