     
     public init?(data: Data) {
         
-        guard data.count == GAPUnprovisionedDeviceBeacon.minLength || data.count == GAPUnprovisionedDeviceBeacon.maxLength
-            else { return nil }
-        
-        guard let beaconType = GAPBeaconType(rawValue: data[0])
+        guard let length = Length(rawValue: data.count)
+            else { return nil }
+        
+        guard let beaconType = GAPBeaconType(rawValue: data[0]),
+            beaconType == type(of: self).beaconType
             else { return nil }
         
         let deviceUUID = UUID(UInt128(littleEndian: UInt128(bytes: (data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15], data[16]))))
+        
         let oobInformationFlags = BitMaskOptionSet<GAPOOBInformationFlag>(rawValue: UInt16(littleEndian: UInt16(bytes: (data[17], data[18]))))
-        var uriHash: UInt32?
-        
-        if data.count == type(of: self).maxLength {
+        
+        let uriHash: UInt32?
+        
+        switch length {
+            
+        case .withoutURI:
+            
+            uriHash = nil
+            
+        case .withURI:
             
             uriHash = UInt32(littleEndian: UInt32(bytes: (data[19], data[20], data[21], data[22])))
         }
         
-        self.init(beaconType: beaconType, deviceUUID: deviceUUID, oobInformationFlags: oobInformationFlags, uriHash: uriHash)
+        self.init(deviceUUID: deviceUUID, oobInformationFlags: oobInformationFlags, uriHash: uriHash)
     }
     
     var data: Data {
         
         var data = Data()
         
-        data.append(beaconType.rawValue)
+        data.append(type(of: self).beaconType.rawValue)
         
         data.append(UInt128(uuid: deviceUUID).littleEndian.data)
         

 */
public struct GAPUnprovisionedDeviceBeacon {
    
    public static let minLength = 19
    
    public static let maxLength = 23
    
    public let beaconType: GAPBeaconType
    
    public let deviceUUID: UUID
    
    public let oobInformationFlags: BitMaskOptionSet<GAPOOBInformationFlag>
    
    public let uriHash: UInt32?
    
    public init(beaconType: GAPBeaconType,
                deviceUUID: UUID,
                oobInformationFlags: BitMaskOptionSet<GAPOOBInformationFlag>, uriHash: UInt32? = nil) {
        
        self.beaconType = beaconType
        self.deviceUUID = deviceUUID
        self.oobInformationFlags = oobInformationFlags
        self.uriHash = uriHash

        }
        
        return data
    }
    
    enum Length: Int {
        
        case withoutURI = 19
        case withURI = 23
    }
}

