Refactor file reading