             
             let difference = aVector - bVector
             let differenceDistance = difference.length()
-            let windowScale = 1.0 / (CGFloat(neighbors * neighbors))
+            let windowScale: CGFloat = 1.0
             totalDistance += differenceDistance * windowScale
         }
         
-        return totalDistance
+        return totalDistance / CGFloat(neighborsRange)
     }
     
     func greedyDynamicTimeWarp(sample: [CGPoint], prototype: [CGPoint]) -> CGFloat {
-        let minNeighborSize = 3
-        let maxNeighborSize = 5
+        let minNeighborSize = 2
+        let maxNeighborSize = 8
         if sample.count < minNeighborSize * 4 || prototype.count < minNeighborSize * 4 {
             return CGFloat.max
         }

    
    func normalizeDigit(inputDigit: DigitStrokes) -> DigitStrokes {
        let targetPointCount = 32
        let totalPoints = inputDigit.reduce(0) {(total, stroke) -> Int in
            return total + stroke.count
        }
        var dropEveryDistance: Double = 1000000.0
        if totalPoints > targetPointCount {
            dropEveryDistance = Double(totalPoints) / Double(totalPoints - targetPointCount)
        }
        
        var inputDigit = inputDigit
        if totalPoints < targetPointCount {
            // We need to insert points
            let newPointCount = targetPointCount - totalPoints
            let insertEveryDistance = CGFloat(totalPoints) / CGFloat(newPointCount)
            var pointIndex = 0
            var insertedToVirtualIndex: CGFloat = 0.0
            
            var newInputDigit: DigitStrokes = []
            for stroke in inputDigit {
                var lastPoint: CGPoint?
                var newStroke: [CGPoint] = []
                for point in stroke {
                    if let lastPoint = lastPoint {
                        while insertedToVirtualIndex + insertEveryDistance < CGFloat(pointIndex) {
                            let ratio = min(CGFloat(pointIndex) - insertedToVirtualIndex , 0.5)
                            let newPoint = CGPointMake(lastPoint.x * ratio + point.x * (1.0 - ratio),
                                lastPoint.y * ratio + point.y * (1.0 - ratio))
                            
                            newStroke.append(newPoint)
                            insertedToVirtualIndex += insertEveryDistance
                        }
                    }
                    newStroke.append(point)
                    lastPoint = point
                    pointIndex++
                }
                newInputDigit.append(newStroke)
            }
            inputDigit = newInputDigit
        }
        
        
        var topLeft: CGPoint?
        var bottomRight: CGPoint?

        var pointIndex = 0
        var droppedDistance: Double = 0
        return inputDigit.map { subPath in
            return subPath.map({ point in
                let x = (point.x - xTranslate) * scale
                let y = (point.y - yTranslate) * scale
                return CGPointMake(x, y)
