Optimization for contour creation