                     let b = Double((line as NSString).substring(with: matches[0].rangeAt(4)))
 
                     if pos != nil && r != nil && g != nil && b != nil {
-                        let color = gradientGetColorAtPosition(gradient, pos!)
-
-                        if color != nil {
-                            color!.r = r!
-                            color!.g = g!
-                            color!.b = b!
+                        if let index = gradientGetIndexOfColorAtPosition(gradient, pos!) {
+                            gradient.colors[index].r = r!
+                            gradient.colors[index].g = g!
+                            gradient.colors[index].b = b!
                         } else {
-                            gradient.colors.append(GradientColor(pos!, r!, g!, b!))
+                            gradient.colors.append(GradientColor(pos: pos!, r: r!, g: g!, b: b!))
                         }
                     }
                 }

    return abs(absA - absB) <= max(absA, absB) * DBL_EPSILON
}

func gradientGetColorAtPosition(_ gradient: Gradient, _ pos: Double) -> GradientColor? {
    for color in gradient.colors {
        if equalEnough(color.pos, pos) {
            return color
        }
    }


    case GETTIME
}

struct GradientColor {
    var pos: Double
    var r, g, b: Double
}

struct Gradient {
    var colors = [GradientColor]()
}

