MergeFunctions: reduce complexity to O(log(N))

Ping