 public class lolApiWrapper: NSObject {
     
     // MARK: Initialised detail
-    var APIKey = ""
-    var region = ""
-    var miniURL = ""
-    var result = NSDictionary();
-    var static_data:Bool = false;
-    
-    public func ApiKey(APIKey: String, region: String = "") -> lolApiWrapper {
+    var APIKey: String!
+    var region: String?
+    var miniURL: String!
+    var result: NSDictionary!
+    var static_data: Bool = false
+    private var debugEnabled: Bool = false
+    
+    var delegate: LolAPIListener?
+    var sharedInstance: lolApiWrapper = lolApiWrapper()
+    
+    public func ApiKey(APIKey: String, region: String?) -> lolApiWrapper {
         self.APIKey = APIKey
         self.region = region
         
         return self
     }
     
+    public func APIWithDebug(APIKey k: String, region r: String?) -> lolApiWrapper {
+        debugEnabled = true
+        
+        return ApiKey(k, region: r)
+    }
     
     // MARK: Retrieve API
     public func get() -> NSDictionary {
-        var apiURL = "";
-        
-        if(self.region == "") {
-            for i in 0...(regions.count-1) {
-                if(!static_data) {
-                    apiURL = APIURL.stringByReplacingOccurrencesOfString("{region}", withString: regions[i], options: NSStringCompareOptions.LiteralSearch, range: nil)
-                } else {
-                    apiURL = STATICURL.stringByReplacingOccurrencesOfString("{region}", withString: regions[i], options: NSStringCompareOptions.LiteralSearch, range: nil)
-                }
-                let URL = apiURL + self.miniURL + (self.miniURL.containsString("?") ? "&" : "?") + "api_key=" + self.APIKey
-                
-                self.result = self.getJSON(URL)
-                
-                if (self.result.count > 0) {
-                    break;
+        guard let r = region else {
+            for r in 0..<regions.count {
+                let finalURL = genURL(forRegion: regions[r])
+                result = getJSON(finalURL)
+                if result.count > 0 {
+                    break
                 }
             }
-        } else {
-            if(!static_data) {
-                apiURL = APIURL.stringByReplacingOccurrencesOfString("{region}", withString: self.region, options: NSStringCompareOptions.LiteralSearch, range: nil)
-            } else {
-                apiURL = STATICURL.stringByReplacingOccurrencesOfString("{region}", withString: self.region, options: NSStringCompareOptions.LiteralSearch, range: nil)
-            }
-            let URL = apiURL + self.miniURL + (self.miniURL.containsString("?") ? "&" : "?") + "api_key=" + self.APIKey
-            self.result = self.getJSON(URL)
+            return result
         }
         
-        
-        print(self.result)
-        
-        return self.result
+        let finalURL = genURL(forRegion: r)
+        result = getJSON(finalURL)
+        
+        if debugEnabled { print(result) }
+        delegate?.didReturnResult(result)
+        
+        return result
+    }
+    
+    private func genURL(forRegion r: String) -> String {
+        let apiURL = ((static_data) ? APIURL : STATICURL).stringByReplacingOccurrencesOfString("{region}", withString: r, options: NSStringCompareOptions.LiteralSearch)
+        
+        let operand = ((miniURL.containsString("?")) ? "&" : "?")
+        let finalURL = "\(apiURL)\(miniURL)\(operand)api_key=\(APIKey)"
+        
+        return finalURL
     }
     
     public func getJSON(urlToRequest: String) -> NSDictionary{

            do {
                jsonDictionary = try NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
            } catch let error as NSError {
                print(error)
            }
        } else {
            print("-------- URL IS INVALID --------\n")
        }
        
        return jsonDictionary

//
//  Created by Mobin Zadeh Kochak on 04/09/2015.
//  Copyright (c) 2015 Mobin Zadeh Kochak. All rights reserved.
//  Edited by Mason Phillips (https://github.com/mathmatrix828/
//  Edited on 30MAY2016
//

import UIKit
