Merge contours with less buggy way