     let end = Point(x: p2.x + a_last.y * q1.y * t, y: p2.y - a_last.y * q1.x * t)
     
     let z0 = a.lazy.map { $0 - a_first }.first { !$0.x.almostZero() || !$0.y.almostZero() }!
-    let z1 = a.reversed().lazy.map { a_last - $0 }.first { !$0.x.almostZero() || !$0.y.almostZero() }!
+    let z1 = a.lazy.map { a_last - $0 }.last { !$0.x.almostZero() || !$0.y.almostZero() }!
     
     if let mid = QuadBezierFitting(start, end, q0 * SDTransform.Rotate(z0.phase), q1 * SDTransform.Rotate(z1.phase)) {
         return limit > 0 && BezierOffsetCurvature(start, mid, end) ? split_half() : [[start, mid, end]]

    if ph0.almostEqual(ph1 + M_PI) || ph0.almostEqual(ph1 - M_PI) {
        if let w = QuadBezierStationary(p0.x, p1.x, p2.x) ?? QuadBezierStationary(p0.y, p1.y, p2.y) {
            let g = Bezier(w, p0, p1, p2)
            if let left = BezierOffset(p0, g, a), let right = BezierOffset(g, p2, a) {
                let angle = ph0 - M_PI_2
                let bezierCircle = BezierCircle.lazy.map { $0 * SDTransform.Rotate(angle) * a + g }
                let i = [bezierCircle[0],
                         bezierCircle[1],
                         bezierCircle[2],
                         bezierCircle[3]]
                let j = [bezierCircle[3],
                         bezierCircle[4],
                         bezierCircle[5],
                         bezierCircle[6]]
                return [[left.0, left.1], i, j, [right.0, right.1]]
            }
        }
    }
    

    
    func split_half() -> [[Point]] {
        let (p_left, p_right) = SplitBezier(0.5, p0, p1, p2)
        let (a_left, a_right) = split_a(half_length)
        return BezierVariableOffset(p0: p_left[0], p1: p_left[1], p2: p_left[2], a_left, limit - 1) + BezierVariableOffset(p0: p_right[0], p1: p_right[1], p2: p_right[2], a_right, limit - 1)
    }
    
    if limit > 0 && BezierOffsetCurvature(p0, p1, p2) {
