Refactor file merging