diff --git a/experimental/Intersection/CurveIntersection.h b/experimental/Intersection/CurveIntersection.h
index d6ca837..f95e028 100644
--- a/experimental/Intersection/CurveIntersection.h
+++ b/experimental/Intersection/CurveIntersection.h
@@ -13,7 +13,7 @@
 bool implicit_matches(const _Line& line1, const _Line& line2);
 bool implicit_matches(const Quadratic& quad1, const Quadratic& quad2);
 void sub_divide(const Cubic& src, double t1, double t2, Cubic& dst);
-void sub_divide(const _Line& src, double t1, double t2, Cubic& dst);
+void sub_divide(const _Line& src, double t1, double t2, _Line& dst);
 void sub_divide(const Quadratic& src, double t1, double t2, Quadratic& dst);
 void tangent(const Cubic& cubic, double t, _Point& result);
 void tangent(const _Line& line, _Point& result);
diff --git a/experimental/Intersection/DataTypes.cpp b/experimental/Intersection/DataTypes.cpp
index 8f46e8e..07e7548 100644
--- a/experimental/Intersection/DataTypes.cpp
+++ b/experimental/Intersection/DataTypes.cpp
@@ -81,14 +81,22 @@
     double t2 = t * t;
     double c = 3 * one_t * t2;
     double d = t2 * t;
-    x = a * cubic[0].x + b * cubic[1].x + c * cubic[2].x + d * cubic[3].x;
-    y = a * cubic[0].y + b * cubic[1].y + c * cubic[2].y + d * cubic[3].y;
+    if (&x) {
+        x = a * cubic[0].x + b * cubic[1].x + c * cubic[2].x + d * cubic[3].x;
+    }
+    if (&y) {
+        y = a * cubic[0].y + b * cubic[1].y + c * cubic[2].y + d * cubic[3].y;
+    }
 }
 
 void xy_at_t(const _Line& line, double t, double& x, double& y) {
     double one_t = 1 - t;
-    x = one_t * line[0].x + t * line[1].x;
-    y = one_t * line[0].y + t * line[1].y;
+    if (&x) {
+        x = one_t * line[0].x + t * line[1].x;
+    }
+    if (&y) {
+        y = one_t * line[0].y + t * line[1].y;
+    }
 }
 
 void xy_at_t(const Quadratic& quad, double t, double& x, double& y) {
@@ -96,6 +104,10 @@
     double a = one_t * one_t;
     double b = 2 * one_t * t;
     double c = t * t;
-    x = a * quad[0].x + b * quad[1].x + c * quad[2].x;
-    y = a * quad[0].y + b * quad[1].y + c * quad[2].y;
+    if (&x) {
+        x = a * quad[0].x + b * quad[1].x + c * quad[2].x;
+    }
+    if (&y) {
+        y = a * quad[0].y + b * quad[1].y + c * quad[2].y;
+    }
 }
diff --git a/experimental/Intersection/EdgeWalker.cpp b/experimental/Intersection/EdgeWalker.cpp
index bf090e7..4f4fc9b 100644
--- a/experimental/Intersection/EdgeWalker.cpp
+++ b/experimental/Intersection/EdgeWalker.cpp
@@ -6,6 +6,7 @@
  * found in the LICENSE file.
  */
 
+#include "CurveIntersection.h"
 #include "LineIntersection.h"
 #include "SkPath.h"
 #include "SkRect.h"
@@ -13,18 +14,37 @@
 #include "SkTDArray.h"
 #include "TSearch.h"
 
-static int lineIntersect(const SkPoint a[2], const SkPoint b[2],
+static int LineIntersect(const SkPoint a[2], const SkPoint b[2],
         double aRange[2], double bRange[2]) {
     _Line aLine = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}};
     _Line bLine = {{b[0].fX, b[0].fY}, {b[1].fX, b[1].fY}};
     return intersect(aLine, bLine, aRange, bRange);
 }
 
-static int lineIntersect(const SkPoint a[2], SkScalar y, double aRange[2]) {
+static int LineIntersect(const SkPoint a[2], SkScalar y, double aRange[2]) {
     _Line aLine = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}};
     return horizontalIntersect(aLine, y, aRange);
 }
 
+static SkScalar LineYAtT(const SkPoint a[2], double t) {
+    _Line aLine = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}};
+    double y;
+    xy_at_t(aLine, t, *(double*) 0, y);
+    return SkDoubleToScalar(y);
+}
+
+static void LineSubDivide(const SkPoint a[2], double startT, double endT,
+        SkPoint sub[2]) {
+    _Line aLine = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}};
+    _Line dst;
+    sub_divide(aLine, startT, endT, dst);
+    sub[0].fX = SkDoubleToScalar(dst[0].x);
+    sub[0].fY = SkDoubleToScalar(dst[0].y);
+    sub[1].fX = SkDoubleToScalar(dst[1].x);
+    sub[1].fY = SkDoubleToScalar(dst[1].y);
+}
+
+
 // functions
 void contourBounds(const SkPath& path, SkTDArray<SkRect>& boundsArray);
 void simplify(const SkPath& path, bool asFill, SkPath& simple);
@@ -84,6 +104,29 @@
     }
 }
 
+struct OutEdge {
+
+    SkTDArray<SkPoint> fPts;
+    SkTDArray<uint8_t> fVerbs;
+};
+
+class OutEdgeBuilder {
+public:
+    void addLine(SkPoint pts[2]) {
+        ;
+        OutEdge* edge;
+        
+        edge = fEdges.append();
+        
+        if (empty) {
+            *edge->fPts.append() = pts[0];
+        }
+        *edge->fPts.append() = pts[1];
+    }
+
+    SkTArray<OutEdge> fEdges;
+};
+
 // Bounds, unlike Rect, does not consider a vertical line to be empty.
 struct Bounds : public SkRect {
     static bool Intersects(const Bounds& a, const Bounds& b) {
@@ -92,14 +135,12 @@
     }
 };
 
-struct Edge;
-
 struct Intercepts {
     SkTDArray<double> fTs;
 };
 
-struct Edge {
-    bool operator<(const Edge& rh) const {
+struct InEdge {
+    bool operator<(const InEdge& rh) const {
         return fBounds.fTop == rh.fBounds.fTop
                 ? fBounds.fLeft < rh.fBounds.fLeft
                 : fBounds.fTop < rh.fBounds.fTop;
@@ -125,7 +166,7 @@
         }
     }
 
-    bool cached(const Edge* edge) {
+    bool cached(const InEdge* edge) {
         // FIXME: in the pathological case where there is a ton of edges, binary search?
         size_t count = fCached.count();
         for (size_t index = 0; index < count; ++index) {
@@ -157,25 +198,36 @@
             ++ptPtr;
         }
         fIntercepts.push_back_n(1);
-        fWinding = winding;
+        if ((fWinding = winding) < 0) { // reverse verbs, pts, if bottom to top
+            size_t index;
+            size_t last = fPts.count() - 1;
+            for (index = 0; index < last; ++index, --last) {
+                SkTSwap<SkPoint>(fPts[index], fPts[last]);
+            }
+            last = fVerbs.count() - 1;
+            for (index = 0; index < last; ++index, --last) {
+                SkTSwap<uint8_t>(fVerbs[index], fVerbs[last]);
+            }
+        }
+        fContainsIntercepts = false;
     }
 
     // temporary data : move this to a separate struct?
-    SkTDArray<const Edge*> fCached; // list of edges already intercepted
+    SkTDArray<const InEdge*> fCached; // list of edges already intercepted
     SkTArray<Intercepts> fIntercepts; // one per verb
     
-
     // persistent data
     SkTDArray<SkPoint> fPts;
     SkTDArray<uint8_t> fVerbs;
     Bounds fBounds;
     signed char fWinding;
+    bool fContainsIntercepts;
 };
 
-class EdgeBuilder {
+class InEdgeBuilder {
 public:
 
-EdgeBuilder(const SkPath& path, bool ignoreHorizontal, SkTArray<Edge>& edges) 
+InEdgeBuilder(const SkPath& path, bool ignoreHorizontal, SkTArray<InEdge>& edges) 
     : fPath(path)
     , fCurrentEdge(NULL)
     , fEdges(edges)
@@ -200,8 +252,8 @@
     }
     int last = count - 1;
     return fPts[0].fY == fPts[last].fY
-            ? fPts[0].fX == fPts[last].fX ? 0 : fPts[0].fX > fPts[last].fX
-            ? 1 : -1 : fPts[0].fY > fPts[last].fY ? 1 : -1;
+            ? fPts[0].fX == fPts[last].fX ? 0 : fPts[0].fX < fPts[last].fX
+            ? 1 : -1 : fPts[0].fY < fPts[last].fY ? 1 : -1;
 }
 
 bool isHorizontal() {
@@ -264,8 +316,8 @@
 
 private:
     const SkPath& fPath;
-    Edge* fCurrentEdge;
-    SkTArray<Edge>& fEdges;
+    InEdge* fCurrentEdge;
+    SkTArray<InEdge>& fEdges;
     SkPoint fPts[4];
     SkPath::Verb fVerb;
     int fPtCount;
@@ -275,41 +327,21 @@
     bool fIgnoreHorizontal;
 };
 
-class WorkEdge {
-public:
-    WorkEdge(const Edge* edge) {
-        fVerbStart = edge->fVerbs.begin();
-        if ((fWinding = edge->fWinding) > 0) {
-            fPts = edge->fPts.begin();
-            fVerb = fVerbStart;
-            fVerbEnd = edge->fVerbs.end();
-        } else {
-            fPts = edge->fPts.end();
-            fVerb = edge->fVerbs.end();
-            fVerbEnd = fVerbStart;
-            next();
-        }
+struct WorkEdge {
+    SkScalar bottom() const {
+        return fPts[verb()].fY;
     }
 
-    SkScalar bottom() const {
-        return fPts[fWinding > 0 ? verb() : 0].fY;
+    void init(const InEdge* edge) {
+        fEdge = edge;
+        fPts = edge->fPts.begin();
+        fVerb = edge->fVerbs.begin();
     }
 
     bool next() {
-        if (fWinding > 0) {
-            fPts += *fVerb;
-            return ++fVerb != fVerbEnd;
-        } else {
-            if (fVerb == fVerbEnd) {
-                return false;
-            }
-            fPts -= *--fVerb;
-            return true; 
-        }
-    }
-
-    const SkPoint* points() const {
-        return fPts;
+        SkASSERT(fVerb < fEdge->fVerbs.end());
+        fPts += *fVerb++;
+        return fVerb != fEdge->fVerbs.end();
     }
 
     SkPath::Verb verb() const {
@@ -317,51 +349,82 @@
     }
 
     int verbIndex() const {
-        return fVerb - fVerbStart;
+        return fVerb - fEdge->fVerbs.begin();
+    }
+    
+    int winding() const {
+        return fEdge->fWinding;
     }
 
-protected:     
+    const InEdge* fEdge;
     const SkPoint* fPts;
     const uint8_t* fVerb;
-    const uint8_t* fVerbEnd;
-    const uint8_t* fVerbStart;
-    int8_t fWinding;
 };
 
+// always constructed with SkTDArray because new edges are inserted
+// this may be a inappropriate optimization, suggesting that a separate array of
+// ActiveEdge* may be faster to insert and search
 struct ActiveEdge {
-    void init(const Edge* test) {
-        fEdge = test;
-        if (!fEdge->fIntercepts.count()) {
-            fBounds = test->fBounds;
-            fPtStart = 0;
-            fPtEnd = test->fPts.count();
-            fVerbStart = 0;
-            fVerbEnd = test->fVerbs.count();
-            fTStart = 0;
-            fTEnd = SK_Scalar1;
-        } else {
-            // FIXME: initialize from intercepts
-
-        }
+    void init(const InEdge* edge) {
+        fWorkEdge.init(edge);
+        initT();
+    }
+    
+    void initT() {
+        fTs = &fWorkEdge.fEdge->fIntercepts[fWorkEdge.verbIndex()].fTs;
+        fTIndex = 0;
     }
 
-    const Edge* fEdge;
-    SkRect fBounds;
-    int fPtStart;
-    int fPtEnd;
-    int fVerbStart;
-    int fVerbEnd;
-    SkScalar fTStart;
-    SkScalar fTEnd;
+    bool nextT() {
+        SkASSERT(fTIndex <= fTs->count());
+        return ++fTIndex == fTs->count() + 1;
+    }
+    
+    bool next() {
+        bool result = fWorkEdge.next();
+        initT();
+        return result;
+    }
+
+    double t() {
+        if (fTIndex == 0) {
+            return 0;
+        }
+        if (fTIndex > fTs->count()) {
+            return 1;
+        }
+        return (*fTs)[fTIndex - 1];
+    }
+
+    WorkEdge fWorkEdge;
+    const SkTDArray<double>* fTs;
+    int fTIndex;
 };
 
+static void addToActive(SkTDArray<ActiveEdge>& activeEdges, const InEdge* edge) {
+    // FIXME: in the pathological case where there is a ton of intercepts, binary search?
+    size_t count = activeEdges.count();
+    for (size_t index = 0; index < count; ++index) {
+        if (edge < activeEdges[index].fWorkEdge.fEdge) {
+            ActiveEdge* active = activeEdges.insert(index);
+            active->init(edge);
+            return;
+        }
+        if (edge == activeEdges[index].fWorkEdge.fEdge) {
+            return;
+        }
+    }
+    ActiveEdge* active = activeEdges.append();
+    active->init(edge);
+}
+
 void simplify(const SkPath& path, bool asFill, SkPath& simple) {
     // turn path into list of edges increasing in y
     // if an edge is a quad or a cubic with a y extrema, note it, but leave it unbroken
     // once we have a list, sort it, then walk the list (walk edges twice that have y extrema's on top)
     //  and detect crossings -- look for raw bounds that cross over, then tight bounds that cross
-    SkTArray<Edge> edges;
-    EdgeBuilder builder(path, asFill, edges);
+    SkTArray<InEdge> edges;
+    InEdgeBuilder builder(path, asFill, edges);
     size_t edgeCount = edges.count();
     simple.reset();
     if (edgeCount == 0) {
@@ -369,24 +432,26 @@
     }
     // returns 1 for evenodd, -1 for winding, regardless of inverse-ness
     int windingMask = (path.getFillType() & 1) ? 1 : -1;
-    SkTDArray<Edge*> edgeList;
+    SkTDArray<InEdge*> edgeList;
     for (size_t index = 0; index < edgeCount; ++index) {
         *edgeList.append() = &edges[index];
     }
-    Edge edgeSentinel;
+    InEdge edgeSentinel;
     edgeSentinel.fBounds.set(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, SK_ScalarMax);
     *edgeList.append() = &edgeSentinel;
     ++edgeCount;
-    QSort<Edge>(edgeList.begin(), edgeCount);
-    Edge** currentPtr = edgeList.begin();
-    Edge* current = *currentPtr;
+    QSort<InEdge>(edgeList.begin(), edgeCount);
+    InEdge** currentPtr = edgeList.begin();
+    InEdge* current = *currentPtr;
     SkScalar y = current->fBounds.fTop;
     SkScalar bottom = current->fBounds.fBottom;
     // walk the sorted edges from top to bottom, computing accumulated winding
+    SkTDArray<ActiveEdge> activeEdges;
+    OutEdgeBuilder outBuilder;
     do {
         // find the list of edges that cross y
-        Edge** lastPtr = currentPtr; // find the edge below the bottom of the first set
-        Edge* last = *lastPtr;
+        InEdge** lastPtr = currentPtr; // find the edge below the bottom of the first set
+        InEdge* last = *lastPtr;
         while (lastPtr != edgeList.end()) {
             if (bottom <= last->fBounds.fTop) {
                 break;
@@ -403,6 +468,7 @@
             } else if (bottom > last->fBounds.fBottom) {
                 bottom = last->fBounds.fBottom;
             }
+            addToActive(activeEdges, last);
             last = *++lastPtr;
         }
         if (asFill && lastPtr - currentPtr <= 1) {
@@ -410,17 +476,21 @@
             SkASSERT(0);
             return;
         }
+
         // find any intersections in the range of active edges
-        Edge** testPtr = currentPtr;
-        Edge* test = *testPtr;
+        InEdge** testPtr = currentPtr;
+        InEdge* test = *testPtr;
         while (testPtr != lastPtr) {
             if (test->fBounds.fBottom > bottom) {
-                WorkEdge wt(test);
+                WorkEdge wt;
+                wt.init(test);
                 do {
-                    // FIXME: add all combinations of curve types
+                    // FIXME: add all curve types
+                    // OPTIMIZATION: if bottom intersection does not change
+                    // the winding on either side of the split, don't intersect
                     if (wt.verb() == SkPath::kLine_Verb) {
                         double wtTs[2];
-                        int pts = lineIntersect(wt.points(), bottom, wtTs);
+                        int pts = LineIntersect(wt.fPts, bottom, wtTs);
                         if (pts) {
                             test->add(wtTs, pts, wt.verbIndex());
                         }
@@ -432,47 +502,106 @@
         testPtr = currentPtr;
         test = *testPtr;
         while (testPtr != lastPtr - 1) {
-            Edge* next = *++testPtr;
-            // OPTIMIZATION: if test and next is inside the winding of outer
-            // edges such that intersecting them is irrelevent, skip them.
+            InEdge* next = *++testPtr;
             if (!test->cached(next)
                     && Bounds::Intersects(test->fBounds, next->fBounds)) {
-                WorkEdge wt(test);
-                WorkEdge wn(next);
+                WorkEdge wt, wn;
+                wt.init(test);
+                wn.init(next);
                 do {
                     // FIXME: add all combinations of curve types
-                    if (wt.verb() == SkPath::kLine_Verb && wn.verb() == SkPath::kLine_Verb) {
+                    if (wt.verb() == SkPath::kLine_Verb
+                            && wn.verb() == SkPath::kLine_Verb) {
                         double wtTs[2], wnTs[2];
-                        int pts = lineIntersect(wt.points(), wn.points(), wtTs, wnTs);
+                        int pts = LineIntersect(wt.fPts, wn.fPts, wtTs, wnTs);
                         if (pts) {
                             test->add(wtTs, pts, wt.verbIndex());
+                            test->fContainsIntercepts = true;
                             next->add(wnTs, pts, wn.verbIndex());
+                            next->fContainsIntercepts = true;
                         }
                     }
                 } while (wt.bottom() <= wn.bottom() ? wt.next() : wn.next());
             }
             test = next;
         }
+
+        // compute bottom taking into account any intersected edges
+        ActiveEdge* activePtr = activeEdges.begin() - 1;
+        ActiveEdge* lastActive = activeEdges.end();
+        while (++activePtr != lastActive) {
+            const InEdge* test = activePtr->fWorkEdge.fEdge;
+            if (!test->fContainsIntercepts) {
+                continue;
+            }
+            WorkEdge wt;
+            wt.init(test);
+            do {
+                // FIXME: add all curve types
+                const Intercepts& intercepts = test->fIntercepts[wt.verbIndex()];
+                const SkTDArray<double>& fTs = intercepts.fTs;
+                size_t count = fTs.count();
+                for (size_t index = 0; index < count; ++index) {
+                    if (wt.verb() == SkPath::kLine_Verb) {
+                        SkScalar yIntercept = LineYAtT(wt.fPts, fTs[index]);
+                        if (bottom > yIntercept) {
+                            bottom = yIntercept;
+                        }
+                    }
+                }
+            } while (wt.next());
+        }
+
         // stitch edge and t range that satisfies operation
         int winding = 0;
-        testPtr = currentPtr;
-        test = *testPtr;
-        while (testPtr != lastPtr - 1) {
+        activePtr = activeEdges.begin() - 1;
+        lastActive = activeEdges.end();
+        SkDebugf("%s y=%g bottom=%g\n", __FUNCTION__, y, bottom);
+        while (++activePtr != lastActive) {
+            const WorkEdge& wt = activePtr->fWorkEdge;
             int lastWinding = winding;
-            winding += test->fWinding;
-            if ((lastWinding & windingMask) == 0 || (winding & windingMask) == 0) {
-                // append pts, verbs, in front of or behind output
-                // a verb may have one or more inter-T value, but only break
-                // curve if curve at t changes winding inclusion
-                ;
+            winding += wt.winding();
+            if (!(lastWinding & windingMask) && !(winding & windingMask)) {
+                continue;
             }
-            test = *++testPtr;
+            do {
+                double currentT = activePtr->t();
+                const SkPoint* points = wt.fPts;
+                bool last;
+                do {
+                    last = activePtr->nextT();
+                    double nextT = activePtr->t();
+                    // FIXME: add all combinations of curve types
+                    if (wt.verb() == SkPath::kLine_Verb) {
+                        SkPoint clippedPts[2];
+                        const SkPoint* clipped;
+                        if (currentT * nextT != 0 || currentT + nextT != 1) {
+                            LineSubDivide(points, currentT, nextT, clippedPts);
+                            clipped = clippedPts;
+                        } else {
+                            clipped = points;
+                        }
+                        SkDebugf("%s line %g,%g %g,%g\n", __FUNCTION__,
+                                clipped[0].fX, clipped[0].fY,
+                                clipped[1].fX, clipped[1].fY);
+                        outBuilder->addLine(clipped);
+                        if (clipped[1].fY >= bottom) {
+                            goto nextEdge;
+                        }
+                    }
+                    currentT = nextT;
+                } while (!last);
+            } while (activePtr->next());
+    nextEdge:
+            ;
         }
+
         y = bottom;
-        while ((*currentPtr)->fBounds.fBottom >= y) {
+        while ((*currentPtr)->fBounds.fBottom <= y) {
             ++currentPtr;
         }
     } while (*currentPtr != &edgeSentinel);
+
     // assemble output path from string of pts, verbs
     ;
 }
diff --git a/experimental/Intersection/LineUtilities.cpp b/experimental/Intersection/LineUtilities.cpp
index f70352a..1394225 100644
--- a/experimental/Intersection/LineUtilities.cpp
+++ b/experimental/Intersection/LineUtilities.cpp
@@ -21,3 +21,12 @@
     reduced[1] = line[different];
     return 1 + different;
 }
+
+void sub_divide(const _Line& line, double t1, double t2, _Line& dst) {
+    _Point delta;
+    tangent(line, delta);
+    dst[0].x = line[0].x - t1 * delta.x;
+    dst[0].y = line[0].y - t1 * delta.y;
+    dst[1].x = line[0].x - t2 * delta.x;
+    dst[1].y = line[0].y - t2 * delta.y;
+}
