Fixed bugs found when trying to use merge.