Fixing bug with contour sorting.