Simplify merging and adopt a more functional style