Refactor file loading