optimize merging with empty branches