Fix get_contour algorithm