Improved merge script