     private var socket: Socket?
         
     private var errorHandler: ((Error) -> ())? = nil
-    private var handlers = [String : [String : (Message) -> ()]]()
+    private var handlers = [String: [String: Registration]]()
     private var replyHandlers = [String: (Response) -> ()]()
     private let replyHandlersMutex = Mutex(recursive: true)
     

    public func register(address: String,
                         id: String? = nil,
                         headers: [String: String]? = nil,
                         handler: @escaping ((Message) -> ())) throws -> String {
        let _id = id ?? uuid()
        if let _ = self.handlers[address] {
            self.handlers[address]![_id] = handler
        } else {
            self.handlers[address] = [_id : handler]
        }

        try send(JSON(["type": "register", "address": address, "headers": headers ?? [String: String]()])) 

        return _id
    }

        self.errorHandler = errorHandler
    }

    // TODO: docs
    public enum Error : Swift.Error {
        case invalidData(data: JSON)
        case serverError(message: String)
        case disconnected(cause: Swift.Error?)
    }

    struct Registration {
        let address: String
        let id: String
        let handler: (Message) -> ()
        let headers: [String: String]
    }
}
