             // update state
             state = .AuthorizationStateApproved
         } else {
-
+            
             let error = NSError(domain:AGAuthzErrorDomain, code:0, userInfo:["NSLocalizedDescriptionKey": "User cancelled authorization."])
             completionHandler(nil, error)
         }
         // finally, unregister
         self.stopObserving()
     }
-
+    
     func parametersFromQueryString(queryString: String?) -> [String: String] {
         var parameters = [String: String]()
         if (queryString != nil) {
-            var parameterScanner: NSScanner = NSScanner(string: queryString!)
+            let parameterScanner: NSScanner = NSScanner(string: queryString!)
             var name:NSString? = nil
             var value:NSString? = nil
-
+            
             while (parameterScanner.atEnd != true) {
                 name = nil;
                 parameterScanner.scanUpToString("=", intoString: &name)
                 parameterScanner.scanString("=", intoString:nil)
-
+                
                 value = nil
                 parameterScanner.scanUpToString("&", intoString:&value)
                 parameterScanner.scanString("&", intoString:nil)
-
+                
                 if (name != nil && value != nil) {
                     parameters[name!.stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!] = value!.stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
                 }
             }
         }
-
+        
         return parameters;
     }
-
+    
     deinit {
         self.stopObserving()
     }
-
+    
     func stopObserving() {
         // clear all observers
         if (applicationLaunchNotificationObserver != nil) {
             NSNotificationCenter.defaultCenter().removeObserver(applicationLaunchNotificationObserver!)
             self.applicationLaunchNotificationObserver = nil;
         }
-
+        
         if (applicationDidBecomeActiveNotificationObserver != nil) {
             NSNotificationCenter.defaultCenter().removeObserver(applicationDidBecomeActiveNotificationObserver!)
             applicationDidBecomeActiveNotificationObserver = nil

            }
        })
    }

    /**
    Gateway to request authorization access.

    :param: completionHandler A block object to be executed when the request operation finishes.
    */
    public func requestAccess(completionHandler: (AnyObject?, NSError?) -> Void) {
        if (self.oauth2Session.accessToken != nil && self.oauth2Session.tokenIsNotExpired()) {
            // we already have a valid access token, nothing more to be done

public let AGAuthzErrorDomain = "AGAuthzErrorDomain"

/**
 The current state that this module is in.
 
 - AuthorizationStatePendingExternalApproval: the module is waiting external approval.
 - AuthorizationStateApproved: the oauth flow has been approved.
 - AuthorizationStateUnknown: the oauth flow is in unknown state (e.g. user clicked cancel).
 */
enum AuthorizationState {
    case AuthorizationStatePendingExternalApproval
    case AuthorizationStateApproved
