new working merge code