More refactoring of crazy file reading.