Added contour detection