Improved the logic of choosing the original branch to compare with