     return gradient
 }
 
-func colorFromGradientRange(_ left: GradientColor, _ right: GradientColor, _ pos: Double, _ r: inout Double, _ g: inout Double, _ b: inout Double) {
+func colorFromGradientRange(_ left: GradientColor, _ right: GradientColor, _ pos: Double) -> (Double, Double, Double) {
     let pos2 = (pos - left.pos) / (right.pos - left.pos)
 
-    r = ((right.r - left.r) * pos2) + left.r
-    g = ((right.g - left.g) * pos2) + left.g
-    b = ((right.b - left.b) * pos2) + left.b
-}
-
-func colorFromGradient(_ gradient: Gradient, _ posInGradient: Double, _ r: inout Double, _ g: inout Double, _ b: inout Double) -> Bool {
+    return (((right.r - left.r) * pos2) + left.r,
+            ((right.g - left.g) * pos2) + left.g,
+            ((right.b - left.b) * pos2) + left.b)
+}
+
+func colorFromGradient(_ gradient: Gradient, _ posInGradient: Double) -> (Double, Double, Double) {
     var pos = posInGradient
 
     if (pos < 0.0) {

                let smoothedDistanceToNextIteration = smoothedDistancesToNextIterationPerPixel[pixelY * imageWidth + pixelX]  // 0 .. <1.0
                let posInGradient = colorOfPreviousIter + smoothedDistanceToNextIteration * (colorOfCurrentIter - colorOfPreviousIter)

                let _ = colorFromGradient(gradient, posInGradient, &r, &g, &b)
            }

            imageData[3 * (pixelY * imageWidth + pixelX) + 0] = UInt8(255.0 * r)

        right = gradient.colors[i]

        if pos >= left.pos && pos <= right.pos {
            return colorFromGradientRange(left, right, pos)
        }

        left = right
    }

    return (0.0, 0.0, 0.0)
}

func mandelbrotCalc(_ imageWidth: Int, _ imageHeight: Int, _ maxIterations: Int, _ centerX: Double, _ centerY: Double, _ height: Double, _ histogram: inout [Int], _ iterationsPerPixel: inout [Int], _ smoothedDistancesToNextIterationPerPixel: inout [Double]) {
