donut merging in contours/ working out logic