 import Foundation
 
 
-let kDefaultsKey = "Defaults"
-let kSecureDefaultsKey = "SecureDefaults"
-
-
-var defaultsDictionary: NSMutableDictionary! = nil
-
-var secureItemsDictionary: NSMutableDictionary! = nil
-
-
-public struct UserDefaultsImpl: UserConfig {
-
-    
+public class UserDefaultsImpl: UserConfig {
+
+    let kDefaultsKey = "Defaults"
+    let kSecureDefaultsKey = "SecureDefaults"
+
+
+    static var defaultsDictionary: NSMutableDictionary! = nil
+    static var secureItemsDictionary: NSMutableDictionary! = nil
+
     public init() {
         
-        if(defaultsDictionary == nil) {
+        if(UserDefaultsImpl.defaultsDictionary == nil) {
             
             let dictionary = Foundation.UserDefaults.standard.dictionary(forKey: kDefaultsKey)
             
             if dictionary != nil {
             
-                defaultsDictionary = NSMutableDictionary(dictionary: dictionary!)
+                UserDefaultsImpl.defaultsDictionary = NSMutableDictionary(dictionary: dictionary!)
             } else {
                 
-                defaultsDictionary = NSMutableDictionary()
-            }
-            
-            let secureDictionary = defaultsDictionary.object(forKey: kSecureDefaultsKey) as? NSDictionary
+                UserDefaultsImpl.defaultsDictionary = NSMutableDictionary()
+            }
+            
+            let secureDictionary = UserDefaultsImpl.defaultsDictionary.object(forKey: kSecureDefaultsKey) as? NSDictionary
             
             if secureDictionary != nil {
             
                 let decryptedDictionary = decryptDictionary(dictionary: secureDictionary!)
                 
-                secureItemsDictionary = NSMutableDictionary(dictionary: decryptedDictionary)
+                UserDefaultsImpl.secureItemsDictionary = NSMutableDictionary(dictionary: decryptedDictionary)
             } else {
                 
-                secureItemsDictionary = NSMutableDictionary()
+                UserDefaultsImpl.secureItemsDictionary = NSMutableDictionary()
             }
         }
     }
     
     public func stringForKey(key: String) -> String? {
         
-        return defaultsDictionary.object(forKey: key) as? String
+        return UserDefaultsImpl.defaultsDictionary.object(forKey: key) as? String
     }
     
     public func secureStringForKey(key: String) -> String? {
         
-        return secureItemsDictionary.object(forKey: key) as? String
+        return UserDefaultsImpl.secureItemsDictionary.object(forKey: key) as? String
     }
     
     public func dictionaryForKey(key: String) -> Dictionary<String, AnyObject>? {
         
-        return defaultsDictionary.object(forKey: key) as? Dictionary
+        return UserDefaultsImpl.defaultsDictionary.object(forKey: key) as? Dictionary
     }
     
     public func dataForKey(key: String) -> NSData? {
         
-        return defaultsDictionary.object(forKey: key) as? NSData
+        return UserDefaultsImpl.defaultsDictionary.object(forKey: key) as? NSData
     }
     
     public func boolForKey(key: String) -> Bool? {
         
-        let number = defaultsDictionary.object(forKey: key) as? NSNumber
+        let number = UserDefaultsImpl.defaultsDictionary.object(forKey: key) as? NSNumber
         
         return number?.boolValue
     }
     
     public func integerForKey(key: String) -> Int? {
         
-        return defaultsDictionary.object(forKey: key) as? Int
+        return UserDefaultsImpl.defaultsDictionary.object(forKey: key) as? Int
         
     }
     

    
        if (value == nil) {
    
            defaultsDictionary.removeObject(forKey: key)
            
        } else {
    
            defaultsDictionary[key] = value
        }
        
        _ = synchronize()

    
    public func setSecureString(value: String?, forKey key: String) {
    
        if(UserDefaultsImpl.secureItemsDictionary == nil) {
    
            UserDefaultsImpl.secureItemsDictionary = NSMutableDictionary()
        }
    
        if (value == nil) {
    
            UserDefaultsImpl.secureItemsDictionary.removeObject(forKey: key)
            
        } else {
    
            UserDefaultsImpl.secureItemsDictionary[key] = value
        }
    }
    
