         return numberOfRequests
     }
 
+    /**
+
+        Removes an entry from the missed requests dictionary
+
+    */
+    public func removeEntry(_ key: String) {
+
+        print("size before is: \(missedRequests.count)")
+        missedRequests.removeValue(forKey: key)
+        print("size after is: \(missedRequests.count)")
+
+    }
+
+    /**
+    
+        Checks if currentEntry is in time range
+ 
+    */
+    public func checkIfValid(currentEntry: JsonRequest) -> Bool {
+
+        let creationTime = currentEntry.creationTime
+        let nowTime = Int(NSDate().timeIntervalSince1970)
+        let pastTime = nowTime - expirationDuration
+
+        if creationTime! > pastTime {
+            return true
+        }
+
+        return false
+    }
+
+    /**
+
+        Save the missed requested if necessary
+
+    */
     public func shutdown() {
         safeMissedRequests()
     }
 
+    /**
+
+        This method saves the missed requests to file with the following structure:
+
+        value-creationtime; value-fullUrl; value-jsonBody
+
+        The key can be ignored because when the missed requests will be loaded a new
+        key will be generated.
+
+    */
     public func safeMissedRequests() {
+
         if self.missedRequests.count > 0 {
 
             let fileURL = try! FileManager.default.url(for: .documentDirectory,
                             in: .userDomainMask, appropriateFor: nil, create: false)
-                    .appendingPathComponent("BreinifyMissedRequests.txt")
+                    .appendingPathComponent(kRequestFullFileName)
 
             if let outputStream = OutputStream(url: fileURL, append: true) {
                 outputStream.open()
 
                 var output = ""
-                for jsonElement in self.missedRequests {
+
+                for (key, jsonElement) in self.missedRequests {
                     output = output
-                            + "\(jsonElement.creationTime)"
-                            + ";"
+                            + "\(jsonElement.creationTime!)"
+                            + kDelimiter
                             + jsonElement.fullUrl
-                            + ";"
+                            + kDelimiter
                             + jsonElement.jsonBody
                             + "\n"
+
+                    let bytesWritten = outputStream.write(output,
+                            maxLength: output.lengthOfBytes(using: .utf8))
+                    if bytesWritten < 0 {
+                        print("write failure")
+                    }
                 }
-                let bytesWritten = outputStream.write(output,
-                        maxLength: output.lengthOfBytes(using: .utf8))
-                if bytesWritten < 0 {
-                    print("write failure")
-                }
+
                 outputStream.close()
             } else {
                 print("Unable to open file")
             }
         }
-    }
-
+
+        // delete file if no entries exists
+        if self.missedRequests.count == 0 {
+
+            let fileManager = FileManager.default
+            let fileName = kRequestFileName
+            let docDirectory = try? fileManager.url(for: .documentDirectory, in: .userDomainMask,
+                    appropriateFor: nil, create: true)
+
+            if let fileURL = docDirectory?.appendingPathComponent(fileName).appendingPathExtension("txt") {
+
+                let filePathName = fileURL.path
+
+                do {
+                    try fileManager.removeItem(atPath: filePathName)
+                } catch {
+                    print("Could not remove file: \(filePathName)")
+                }
+                    
+            }
+        }
+    }
+
+    /**
+    
+        This method loads the saved requests from file. Assuming the following structure:
+
+        value-creationtime; value-fullUrl; value-jsonBody
+
+        For each loaded line a new key will be generated.
+
+    */
     public func loadMissedRequests() {
 
         if self.missedRequests.count == 0 {
 
-            let fileName = "BreinifyMissedRequests"
+            let fileName = kRequestFileName
             let docDirectory = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask,
                     appropriateFor: nil, create: true)
 

                    let fileContent = inString.components(separatedBy: .newlines)

                    for line in fileContent {
                        let element = line.components(separatedBy: ";")

                        if element.count >= 3 {
                            print(element)
                            let unixTimestamp = Int(element[0])!
                            let fullUrl = element[1]
                            let jsonBody = element[2]

                            addRequest(timeStamp: unixTimestamp, fullUrl: fullUrl, json: jsonBody)
                        }
                    }
                } catch {

        updateTimer?.invalidate()
        updateTimer = nil
    }

    // dictionary of UUID to jsonRequest (unixTimestamp, fullUrl, jsonString)
    var missedRequests = [String: JsonRequest]()

    // contains the unixTimestamp when the failure was detected
    var failureTime = 0.0

    // contains the expiration Duration (5 minutes in seconds)
    var expirationDuration = 5 * 60 * 60

    /// instance for processing unsent requests
    var updateTimer: Timer?

    /// contains the background interval
    var interval = 60.0

    /// contains the delimiter between each element of the structure
    let kDelimiter = "°"

    /// contains the filename for saved requests
    let kRequestFileName = "BreinifyMissedRequests"

    /// contains the full filename for save requests
    let kRequestFullFileName = "BreinifyMissedRequests.txt"

    public func configure() {
        updateTimer = Timer.scheduledTimer(timeInterval: interval,
