updated contour detection