Vastly improved merge function
Vastly improved merge function