Improve cloud merge algorithm