Separate out merge code