                 let proximityEvent = trigger[id]
                 // Represents  the UNIX current time in milliseconds
                 let now = Int64(Date().timeIntervalSince1970 * 1000)
-                if let proximityEventCreatedAt = proximityEvent?.createdAt {
-                    let gap = now - proximityEventCreatedAt
-                    let truncatedGap = Int(truncatingBitPattern: gap)
-                    if truncatedGap > refreshTimer {
-                        // Send the refreshing proximity event based on the timer
-                        let newProximityEvent = ProximityEvent.init(deviceId: id, distance: distance)
-                        let deviceId = "NEED CHANGE"
-                        sendProximityEvent(deviceId: deviceId, proximityEvent: newProximityEvent) {(_ proximityEvent) in
-                            if let pe = proximityEvent {
-                                self.addProximityEvent(deviceId: id, proximityEvent: pe, clProximity: clProximity)
-                            }
+                guard let proximityEventCreatedAt = proximityEvent?.createdAt else {
+                    return
+                }
+                let gap = now - proximityEventCreatedAt
+                let truncatedGap = Int(truncatingBitPattern: gap)
+                if truncatedGap > refreshTimer {
+                    // Send the refreshing proximity event based on the timer
+                    let newProximityEvent = ProximityEvent.init(deviceId: id, distance: distance)
+                    let deviceId = "NEED CHANGE"
+                    sendProximityEvent(deviceId: deviceId, proximityEvent: newProximityEvent) {(_ proximityEvent) in
+                        guard let pe = proximityEvent else {
+                            return
                         }
-                    } else {
-                        // Do something when it doesn't need to be refreshed
+                        self.addProximityEvent(deviceId: id, proximityEvent: pe, clProximity: clProximity)
                     }
+                } else {
+                    // Do something when it doesn't need to be refreshed
                 }
             }
         }

            var beaconsId: [String] = []
            beaconsId = fromArray
            if beaconsId.contains(deviceId) {
                if let index = beaconsId.index(of: deviceId) {
                    beaconsId.remove(at: index)
                }
            }
            return beaconsId
        }

                    let proximityEvent = ProximityEvent.init(deviceId: id, distance: distance)
                    let deviceId = "NEED CHANGE to a guard"
                        sendProximityEvent(deviceId: deviceId, proximityEvent: proximityEvent) {(_ proximityEvent) in
                            guard let pe = proximityEvent else {
                                return
                            }
                            self.addProximityEvent(deviceId: id, proximityEvent: pe, clProximity: clProximity)
                    }
                } else {
                    //this id is already triggered and might need to be refresh -> refreshTriggers()
