         }
         else
         {
+            guard let uuid = proximityUUID else {
+                print("Beacon UUID is not valid")
+                return
+            }
             let region = CLBeaconRegion(proximityUUID: uuid, major: major, minor: minor, identifier: identifier)
-            let manufacturerData = identifier.data(using: String.Encoding.utf8, allowLossyConversion: false)
-            let theUUid = CBUUID(nsuuid: uuid)
-            let dataToBeAdvertised:[String: Any] = [
-                CBAdvertisementDataLocalNameKey: "Patriot Control Panel",
-                CBAdvertisementDataManufacturerDataKey: manufacturerData,
-                CBAdvertisementDataServiceDataKey: [theUUid]
-            ]
-            
-            peripheral.startAdvertising(dataToBeAdvertised)
+            if let dataToBeAdvertised = region.peripheralData(withMeasuredPower: nil) as? [String: Any]
+            {
+                peripheral.startAdvertising(dataToBeAdvertised)
+            }
+            else
+            {
+                print("Unable to start beacon")
+            }
         }
     }
     

        
        let queue = DispatchQueue.global()
        peripheralManager = CBPeripheralManager(delegate: self, queue: queue)
//        if let manager = peripheralManager {  // Is this needed? delegate is set above
//            manager.delegate = self
//        }
    }
    
    

class ViewController: UICollectionViewController
{
    fileprivate var peripheralManager: CBPeripheralManager?
    fileprivate let proximityUUID = UUID(uuidString: "50F415E3-85E4-40E1-A0A9-36943E07690F")
    fileprivate let beaconServiceName = "Patriot Location"
    fileprivate let identifier = Bundle.main.bundleIdentifier!
    fileprivate var major: CLBeaconMajorValue = 1
    fileprivate var minor: CLBeaconMinorValue = 0
