update and cleanup of contour