       else
         t = @containingTriangle p
         [a, b, c] = t.vertices()
-        seq([a, b], [b, c], [c, a]).reduce subdivide(this, t, p), (T, [u, v]) ->
+        seq([b, a], [c, b], [a, c]).reduce subdivide(this, t, p), (T, [u, v]) ->
           if T.sideOf(u, v, p) == 0
-            w = T.third v, u
-            resolve doFlips flip(T, u, v), seq [u, w], [w, v]
+            w = T.third u, v
+            if w?
+              resolve doFlips flip(T, u, v), seq [u, w], [w, v]
+            else
+              T
           else
             resolve doFlips T, seq [u, v]
 

        if t.mustFlip r, s
          console.log "Delaunay condition fails for #{u},#{v},#{w},#{x})", ->

test()

      else
        [a, b] = stack.first()
        if T.mustFlip a, b
          c = T.third a, b
          recur -> doFlips flip(T, a, b), seq([a,c], [c,b]).concat stack.rest()
        else
          recur -> doFlips T, stack.rest()
