         // remove, just in case resubscription fails
         remove(subscription: subscription)
         
+        let failureClosure = { (error: NSError) -> Void in
+            subscription.subscriber?.subscriptionDidFail(self)
+            
+            if let completion = completion {
+                completion(result: .Failure(error))
+            }
+        }
+        
         // re-subscribe only if subscriber still exists
         if subscription.subscriber == nil {
-            if let completion = completion {
-                completion(result: .Failure(createError("Subscriber doesn't exist anymore")))
-            }
+            failureClosure(createError("Subscriber doesn't exist anymore"))
             return
         }
         
-        let parameters = UPnPEventSubscribeRequestSerializer.Parameters(callBack: _eventCallBackURL!, timeout: _defaultSubscriptionTimeout)
-        
-        _subscribeSessionManager.SUBSCRIBE(subscription.eventURLString, parameters: parameters, success: { (task: NSURLSessionDataTask, responseObject: AnyObject?) -> Void in
-            let response: UPnPEventSubscribeResponseSerializer.Response! = responseObject as? UPnPEventSubscribeResponseSerializer.Response
-            if response == nil {
-                if let completion = completion {
-                    completion(result: .Failure(createError("Failure serializing event subscribe response")))
-                }
+        self.eventCallBackURL({ [unowned self] (eventCallBackURL: NSURL?) -> Void in
+            let eventCallBackURL: NSURL! = eventCallBackURL
+            if eventCallBackURL == nil {
+                failureClosure(createError("Event call back URL could not be created"))
                 return
             }
             
-            let now = NSDate()
-            let expiration = now.dateByAddingTimeInterval(NSTimeInterval(response.timeout))
-            
-            subscription.update(response.subscriptionID, expiration: expiration)
-            
-            LogInfo("Successfully re-subscribed with timeout: \(response.timeout/60) mins: \(subscription)")
-            
-            self.add(subscription: subscription, completion: { () -> Void in
-                if let completion = completion {
-                    completion(result: .Success(subscription))
-                }
-            })
-            }, failure: { (task: NSURLSessionDataTask?, error: NSError) -> Void in
-                LogError("Failed to re-subscribe: \(subscription)\nerror: \(error)")
-                
-                subscription.subscriber?.subscriptionDidFail(self)
-                
-                if let completion = completion {
-                    completion(result: .Failure(error))
-                }
+            let parameters = UPnPEventSubscribeRequestSerializer.Parameters(callBack: eventCallBackURL, timeout: self._defaultSubscriptionTimeout)
+            
+            self._subscribeSessionManager.SUBSCRIBE(subscription.eventURLString, parameters: parameters, success: { (task: NSURLSessionDataTask, responseObject: AnyObject?) -> Void in
+                let response: UPnPEventSubscribeResponseSerializer.Response! = responseObject as? UPnPEventSubscribeResponseSerializer.Response
+                if response == nil {
+                    failureClosure(createError("Failure serializing event subscribe response"))
+                    return
+                }
+                
+                let now = NSDate()
+                let expiration = now.dateByAddingTimeInterval(NSTimeInterval(response.timeout))
+                
+                subscription.update(response.subscriptionID, expiration: expiration)
+                
+                LogInfo("Successfully re-subscribed with timeout: \(response.timeout/60) mins: \(subscription)")
+                
+                self.add(subscription: subscription, completion: { () -> Void in
+                    if let completion = completion {
+                        completion(result: .Success(subscription))
+                    }
+                })
+                }, failure: { (task: NSURLSessionDataTask?, error: NSError) -> Void in
+                    LogError("Failed to re-subscribe: \(subscription)\nerror: \(error)")
+                    
+                    failureClosure(error)
+            })
         })
     }
     

    private let _unsubscribeSessionManager = AFHTTPSessionManager()
    private let _defaultSubscriptionTimeout: Int = 1800
    private let _eventCallBackPath = "/Event/\(NSUUID().dashlessUUIDString)"
    private var _eventCallBackURL: NSURL? {
        if let serverURL = _httpServer.serverURL {
            return NSURL(string: _eventCallBackPath, relativeToURL: serverURL)!
        }
        
        return nil
    }
    /// Calling this on the main thread is not recommended as it will block until completed, blocking the main thread is a no-no
    private var subscriptions: [String: Subscription] {
        var subscriptions: [String: Subscription]!
        dispatch_sync(_concurrentSubscriptionQueue, { () -> Void in
            // Dictionaries are structures and therefore copied when assigned to a new constant or variable
            subscriptions = self._subscriptions
        })
        return subscriptions
    }
    
    init() {
        _subscribeSessionManager.requestSerializer = UPnPEventSubscribeRequestSerializer() as AFHTTPRequestSerializer

    
    /// Subscribers should hold on to a weak reference of the subscription object returned. It's ok to call subscribe for a subscription that already exists, the subscription will simply be looked up and returned.
    func subscribe(subscriber: UPnPEventSubscriber, eventURL: NSURL, completion: ((result: Result<AnyObject>) -> Void)? = nil) {
        let failureClosure = { (error: NSError) -> Void in
            if let completion = completion {
                completion(result: .Failure(error))
            }
        }
        
        let eventURLString: String! = eventURL.absoluteString
        if eventURLString == nil {
            if let completion = completion {
                failureClosure(createError("Event URL does not exist"))
            }
            return
        }
        
        // check if subscription for event URL already exists
        subscriptions { [unowned self] (subscriptions: [String: Subscription]) -> Void in
            if let subscription = subscriptions[eventURLString] {
                if let completion = completion {
                    completion(result: .Success(subscription))
                }
                return
            }
            
            self.eventCallBackURL({ [unowned self] (eventCallBackURL: NSURL?) -> Void in
                let eventCallBackURL: NSURL! = eventCallBackURL
                if eventCallBackURL == nil {
                    failureClosure(createError("Event call back URL could not be created"))
                    return
                }
                
                LogInfo("event callback url: \(eventCallBackURL)")
                
                let parameters = UPnPEventSubscribeRequestSerializer.Parameters(callBack: eventCallBackURL, timeout: self._defaultSubscriptionTimeout)
                
                self._subscribeSessionManager.SUBSCRIBE(eventURL.absoluteString!, parameters: parameters, success: { (task: NSURLSessionDataTask, responseObject: AnyObject?) -> Void in
                    let response: UPnPEventSubscribeResponseSerializer.Response! = responseObject as? UPnPEventSubscribeResponseSerializer.Response
                    if response == nil {
                        failureClosure(createError("Failure serializing event subscribe response"))
                        return
                    }
                    
                    let now = NSDate()
                    let expiration = now.dateByAddingTimeInterval(NSTimeInterval(response.timeout))
                    
                    let subscription = Subscription(subscriptionID: response.subscriptionID, expiration: expiration, subscriber: subscriber, eventURLString: eventURL.absoluteString!, manager: self)
                    
                    LogInfo("Successfully subscribed with timeout: \(response.timeout/60) mins: \(subscription)")
                    
                    self.add(subscription: subscription, completion: { () -> Void in
                        if let completion = completion {
                            completion(result: .Success(subscription))
                        }
                    })
                    }, failure: { (task: NSURLSessionDataTask?, error: NSError) -> Void in
                        LogError("Failed to subscribe to event URL: \(eventURL.absoluteString!)\nerror: \(error)")
                        failureClosure(error)
                })
            })
        }
    }
    
    func unsubscribe(subscription: Any, completion: ((result: EmptyResult) -> Void)? = nil) {
