A contour dataset is a common source of data in biomedical imaging and GIS. In practice, many contour datasets violate key assumptions: contours self-intersect or intersect other contours, which can disrupt the performance of algorithms. We call such data dirty. Avoiding this issue, algorithms in the literature assume clean data. This paper considers the issue of dirty datasets, in the context of nesting. Contours are often nested inside other contours, and the nesting level of a contour is important, as it affects the position of the inside of the shape. This paper analyzes the nesting of a dirty dataset, then shows how to use this nesting analysis to repair the data. A theme is the power of image space algorithms in the presence of noise. Image space algorithms for polygon area and Boolean operations of polygons are provided.