     
     var lock:NSRecursiveLock = NSRecursiveLock()
     
-    
+        
     override init(){
         super.init()
     }

        before.removeObject(mapView.userLocation)
        var after = NSSet(array: annotations)
        var toKeep = NSMutableSet(set: before)
        toKeep.intersectSet(after)
        var toAdd = NSMutableSet(set: after)
        toAdd.minusSet(toKeep)
        var toRemove = NSMutableSet(set: before)
        toRemove.minusSet(after)
        
        dispatch_async(dispatch_get_main_queue())  {
            mapView.addAnnotations(toAdd.allObjects)

        let maxX:Int = Int(floor(MKMapRectGetMaxX(rect) * scaleFactor))
        let minY:Int = Int(floor(MKMapRectGetMinY(rect) * scaleFactor))
        let maxY:Int = Int(floor(MKMapRectGetMaxY(rect) * scaleFactor))

        var clusteredAnnotations = [MKAnnotation]()

        lock.lock()

        for i in minX...maxX {

            for j in minY...maxY {

                let mapPoint = MKMapPoint(x: Double(i)/scaleFactor, y: Double(j)/scaleFactor)
                
                let mapSize = MKMapSize(width: 1.0/scaleFactor, height: 1.0/scaleFactor)
