Refactor file reading code to be backwards compatible