         }
     }
 
-    private func toJsonString(data: NSData) -> String {
-        if let jsonstring = NSString(data: data as Data, encoding: String.Encoding.utf8.rawValue) {
-            return jsonstring as String
+    private func toJsonString(data: Data) -> String {
+        if let jsonstring = String(data: data, encoding: .utf8) {
+            return jsonstring
         } else {
             return ""
         }
     }
 
-
     func generateRandomNumberAsString() -> String {
         return String(arc4random_uniform(999999))
     }
 
-
-    func log<T>( _ message:@autoclosure () -> T, level:LogLevel, filename:String, line:Int) {
+    func log<T>( _ message: @autoclosure () -> T, level: LogLevel, filename: String, line: Int) {
         if level.rawValue < SlimLogglyConfig.logglyLogLevel.rawValue {
             // don't log
             return
         }
 
         var jsonstr = ""
-        let mutableDict:NSMutableDictionary = NSMutableDictionary()
+        let mutableDict: NSMutableDictionary = NSMutableDictionary()
         var messageIsaDictionary = false
-        if let msgdict = message() as? NSDictionary {
-            if let nsmsgdict = msgdict as? [NSObject : AnyObject] {
-                mutableDict.addEntries(from: nsmsgdict)
-                messageIsaDictionary = true
-            }
+        if let msgdict = message() as? [NSObject : AnyObject] {
+            mutableDict.addEntries(from: msgdict)
+            messageIsaDictionary = true
         }
         if !messageIsaDictionary {
             mutableDict.setObject("\(message())", forKey: "rawmsg" as NSCopying)
         }
         mutableDict.setObject(level.string, forKey: "level" as NSCopying)
-        mutableDict.setObject(dateFormatter.string(from: NSDate() as Date), forKey: "timestamp" as NSCopying)
+        mutableDict.setObject(dateFormatter.string(from: Date()), forKey: "timestamp" as NSCopying)
         mutableDict.setObject("\(filename):\(line)", forKey: "sourcelocation" as NSCopying)
         mutableDict.addEntries(from: standardFields as [NSObject : AnyObject])
         if let user = self.userid {

        }
    }

    private func traceMessage(msg:String) {
        if SlimConfig.enableConsoleLogging && SlimLogglyConfig.logglyLogLevel == LogLevel.trace {
            print(msg)
        }
    }
}



class SlimLogglyDestination: LogDestination {

    var userid: String?
    fileprivate let dateFormatter = DateFormatter()
    fileprivate var buffer: [String] = []
    fileprivate var backgroundTaskIdentifier: UIBackgroundTaskIdentifier = UIBackgroundTaskInvalid
    fileprivate lazy var standardFields: [String: String] = {
        var dict: [String: String] = [:]
        dict["lang"] = Locale.preferredLanguages[0]
        if let infodict = Bundle.main.infoDictionary {
            if let appname = infodict["CFBundleName"] as? String {
