   
   func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {
     guard let serviceData = advertisementData[CBAdvertisementDataServiceDataKey] as? [NSObject : AnyObject] else { return }
-    guard isAdvertisingURL(serviceData) else { return }
-    
-    if let url = URLForFrame(serviceData) {
-      callback([
-        "url": url.absoluteString,
-        "distance": -1
-      ])
-    }
+    guard isUrlType(serviceData) else { return }
+    guard let frame = getFrameData(serviceData) else { return }
+    
+    let bytes = getFrameBytes(frame)
+    guard let url = getUrl(bytes) else { return }
+    let distance = getDistance(bytes, rssi: RSSI.doubleValue)
+    
+    callback([
+      "url": url,
+      "distance": distance
+    ])
   }
   
   private func startScanningSynchronized() {

    frameData.getBytes(&frameBytes, length: count)
    
    return frameBytes[0] == 0x10
  } else {
    return data?.length > 0
  }
}

private func URLForFrame(advertisementFrameList: [NSObject : AnyObject]) -> NSURL? {
  let uribeaconUUID = CBUUID(string: "FED8")
  var data = advertisementFrameList[uribeaconUUID] as? NSData
  if (data == nil) {
    let eddystoneUUID = CBUUID(string: "FEAA")
    data = advertisementFrameList[eddystoneUUID] as? NSData
    if (data != nil) {
      return parseBeacon(data)
    }
    return nil
  } else {
    return parseBeacon(data)
  }
}

private func parseBeacon(frameData: NSData?) -> NSURL? {
  if (frameData == nil || frameData?.length == 0) {
    return nil
  }
  var frameBytes = [UInt8](count: frameData!.length, repeatedValue: 0)
  frameData!.getBytes(&frameBytes, length: frameData!.length)

  let schemeByte = frameBytes[2]
  let scheme = getScheme(schemeByte)
  
  var result = scheme
  for i in 3..<frameData!.length {
    result.appendContentsOf(getString(frameBytes[i]))
  }
  
  return NSURL(string: result)
}

private func getScheme(char: UInt8) -> String {

  }
}

private func isUrlType(advertisementFrameList: [NSObject : AnyObject]) -> Bool {
  let eddystoneUUID = CBUUID(string: "FEAA")
  let uribeaconUUID = CBUUID(string: "FED8")
  let data = advertisementFrameList[uribeaconUUID]
  
  if (data == nil) {
    guard let frameData = advertisementFrameList[eddystoneUUID] as? NSData else { return false }
    guard frameData.length > 1 else { return false }
