Merge remote-tracking branch 'upstream/master' into origin/master
diff --git a/LICENSE b/LICENSE
index bafd6d5..d955a86 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,22 +1,11 @@
-The MIT License (MIT)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
 
-Copyright (c) 2015 Brandon Shelley
+    http://www.apache.org/licenses/LICENSE-2.0
 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
\ No newline at end of file
diff --git a/README.md b/README.md
index 7a83136..55637e6 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,13 @@
 [![Codacy Badge](https://api.codacy.com/project/badge/grade/034bc34302b646bf932c7c0307e0e313)](https://www.codacy.com/app/remus/usergrid-nodejs)
-[![Travis CI Badge](https://travis-ci.org/r3mus/usergrid-nodejs.svg?branch=master)](https://travis-ci.org/r3mus/usergrid-nodejs)
+[![Travis CI Badge](https://travis-ci.org/brandonscript/usergrid-nodejs.svg?branch=master)](https://travis-ci.org/brandonscript/usergrid-nodejs)
+[![npm version](https://badge.fury.io/js/usergrid.svg)](https://badge.fury.io/js/usergrid)
 
 # usergrid-nodejs
 Node.js SDK 2.0 for Usergrid 
 
 Version 2.0 of this SDK is currently a work in progress; documentation and implementation are subject to change.
 
-**Note:** This Node.js SDK 2.0 for Usergrid is **not** backwards compatible with 0.1X versions of the SDK. If your application is dependent on the 0.1X set of Node.js APIs, you will need to continue using the 0.1X version (see below for installation instructions)._
+_**Note:** This Node.js SDK 2.0 for Usergrid is **not** backwards compatible with 0.1X versions of the SDK. If your application is dependent on the 0.1X set of Node.js APIs, you will need to continue using the 0.1X version (see below for installation instructions)._
 
 ## Current Release
 
@@ -20,7 +21,7 @@
 ## Known Issues
 
 - Native support for push notifications is slated for RC2. Workaround is to send a regular POST request to `'devices/<device_ID>/notifications'`
-- There is no clean way to require submodules (e.g. `UsergridClient` or `UsergridEntity`) modules without referencing the full path to `../lib/client`.
+- There is no clean way to require submodules (e.g. `UsergridClient` or `UsergridEntity`) modules without referencing the full path to `../lib/<class>`.
 - Any other functionality that is missing or expected, please open an issue.
 
 ## Installation
@@ -43,207 +44,556 @@
 
 ## Usage
 
-_Note: This section is a work in progress. In its current release candidate state, this SDK is only recommended for developers familiar with Usergrid, Node.js, and preferably Mocha tests, and is not recommended for production applications. For more advance and comprehensive usage, see `/tests`._
+_**Note:** This section is a work in progress. In its current release candidate state, this SDK is only recommended for developers familiar with Usergrid, Node.js, and ideally Mocha tests. It is not recommended for production applications. For additional advanced/comprehensive usage, see `/tests`._
+
+The Usergrid Node.js SDK is built on top of [request](https://github.com/request/request). As such, it behaves almost as a drop-in replacement. Where you would expect a standard error-first callback from request, the same is true of the Usergrid SDK methods. Where you would expect a response object as the second parameter in the callback, the same is true for the Usergrid SDK.
+
 
 ### Initialization
 
-There are two fundamental ways to implement the Usergrid Node.js SDK: 
+There are two different ways of initializing the Usergrid Node.js SDK: 
 
-1. The singleton pattern is both convenient and enables the developer to use a globally available and always-initialized instance of Usergrid. 
+1. The singleton pattern is both convenient and enables the developer to use a globally available and always-initialized shared instance of Usergrid. 
 
-	    var Usergrid = require('usergrid')
-	    Usergrid.init({
-	        orgId: '<org-id>',
-	        appId: '<app-id>'
-	    })
+	```js
+	var Usergrid = require('usergrid')
+	Usergrid.init({
+	    orgId: '<org-id>',
+	    appId: '<app-id>'
+	})
 	    
-	    // or you can load from a config file; see config.sample.json
+	// or you can load from a config file; see config.sample.json
 	    
-	    var Usergrid = require('usergrid')
-	    Usergrid.init() // defaults to use config.json
-    
-2. The Instance pattern enables the develper to manage instances of the Usergrid client independently and in an isolated fashion. The primary use-case for this is when an application connects to multiple Usergrid targets:
+	var Usergrid = require('usergrid')
+	Usergrid.init() // defaults to use config.json
+	```
+**Config File:**  Optionally, you can use a config file to provide the usergrid credentials for your app.  The usergrid module crawls your App file structure to find files named `usergrid.json` or a `config.json`.  If there are multiple files with one of these names present at different locations under the app, only one of them will be used and the others are ignored.  This may cause use of an unintended backend.  Please make sure you have only one of these files present in the root and subdirectories of your app.
 
-	    var UsergridClient = require('./node_modules/usergrid/lib/client')
-	    var client = new UsergridClient(config)
+2. The instance pattern enables the developer to manage instances of the Usergrid client independently and in an isolated fashion. The primary use-case for this is when an application connects to multiple Usergrid targets.
 
-_Note: The following examples assume you are using the `Usergrid` shared instance. If you've implemented the instance pattern instead, simply replace `Usergrid` with your client instance variable. See `/tests` for advanced usage._
+	```js
+	var UsergridClient = require('./node_modules/usergrid/lib/client')
+	var client = new UsergridClient(config)
+	```
+
+_**Note:** Examples in this readme assume you are using the `Usergrid` shared instance. If you've implemented the instance pattern instead, simply replace `Usergrid` with your client instance variable. See `/tests` for additional examples._
 
 ## RESTful operations
 
-The Usergrid Node.js SDK is built on top of [request](https://github.com/request/request). As such behaves almost as a drop-in replacement. Where you would expect a standard error-first callback from request, the same is true of the Usergrid SDK methods.
+When making any RESTful call, a `type` parameter (or `path`) is always required. Whether you specify this as an argument, in an object as a parameter, or as part of a `UsergridQuery` object is up to you.
 
-When making any RESTful call, a `type` parameter (or `path`) is always required. Whether you specify this as an argument or in an object as a parameter is up to you.
+### GET()
 
-### GET requests
+To get entities in a collection:
 
-**GET entities in a collection**
-
-    Usergrid.GET('collection', function(err, usergridResponse, entities) {
-        // entities is an array of UsergridEntity objects
-    })
+```js
+Usergrid.GET('collection', function(error, usergridResponse, entities) {
+    // entities is an array of UsergridEntity objects
+})
+```
     
-**GET a specific entity in a collection by uuid or name**
+To get a specific entity in a collection by uuid or name:
 
-    Usergrid.GET('collection', '<uuid-or-name>', function(err, usergridResponse, entity) {
-        // entity, if found, is a UsergridEntity object
-    })
+```js
+Usergrid.GET('collection', '<uuid-or-name>', function(error, usergridResponse, entity) {
+    // entity, if found, is a UsergridEntity object
+})
+```
     
-**GET specific entities in a collection by passing a UsergridQuery object**
+To get specific entities in a collection by passing a UsergridQuery object:
 
-    var query = new UsergridQuery('cats')
-                                 .gt('weight', 2.4)
-                                 .contains('color', 'bl*')
-                                 .not
-                                 .eq('color', 'blue')
-                                 .or
-                                 .eq('color', 'orange')
-                                 
-    // this will build out the following query:
-    // select * where weight > 2.4 and color contains 'bl*' and not color = 'blue' or color = 'orange'
+```js
+var query = new UsergridQuery('cats')
+                             .gt('weight', 2.4)
+                             .contains('color', 'bl*')
+                             .not
+                             .eq('color', 'blue')
+                             .or
+                             .eq('color', 'orange')
+                             
+// this will build out the following query:
+// select * where weight > 2.4 and color contains 'bl*' and not color = 'blue' or color = 'orange'
     
-    Usergrid.GET(query, function(err, usergridResponse) {
-        // entities is an array of UsergridEntity objects matching the specified query
-    })
+Usergrid.GET(query, function(error, usergridResponse) {
+    // entities is an array of UsergridEntity objects matching the specified query
+})
+```
     
-### POST and PUT requests
+### POST() and PUT()
 
 POST and PUT requests both require a JSON body payload. You can pass either a standard JavaScript object or a `UsergridEntity` instance. While the former works in principle, best practise is to use a `UsergridEntity` wherever practical. When an entity has a uuid or name property and already exists on the server, use a PUT request to update it. If it does not, use POST to create it.
 
-**POST (create) a new entity in a collection**
+To create a new entity in a collection (POST):
 
-    var entity = new UsergridEntity({
+```js
+var entity = new UsergridEntity({
+    type: 'restaurant',
+    restaurant: 'Dino's Deep Dish,
+    cuisine: 'pizza'
+})
+    
+// or
+    
+var entity = {
+    type: 'restaurant',
+    restaurant: 'Dino's Deep Dish,
+    cuisine: 'pizza'
+}
+    
+Usergrid.POST(entity, function(error, usergridResponse, entity) {
+    // entity should now have a uuid property and be created
+})
+    
+// you can also POST an array of entities:
+
+var entities = [
+    new UsergridEntity({
         type: 'restaurant',
         restaurant: 'Dino's Deep Dish,
         cuisine: 'pizza'
-    })
-    
-    // or
-    
-    var entity = {
-        type: 'restaurant',
-        restaurant: 'Dino's Deep Dish,
-        cuisine: 'pizza'
-    }
-    
-    Usergrid.POST(entity, function(err, usergridResponse, entity) {
-        // entity should now have a uuid property and be created
-    })
-    
-    // you can also POST an array of entities:
-
-    var entities = [
-	    new UsergridEntity({
-	        type: 'restaurant',
-	        restaurant: 'Dino's Deep Dish,
-	        cuisine: 'pizza'
-	    }), 
-	    new UsergridEntity({
-	        type: 'restaurant',
-	        restaurant: 'Pizza da Napoli',
-	        cuisine: 'pizza'
-	    })
-    ]
-    
-    Usergrid.POST(entities, function(err, usergridResponse, entities) {
-        //
-    })
-    
-**PUT (update) an entity in a collection**
-
-    var entity = new UsergridEntity({
+    }), 
+    new UsergridEntity({
         type: 'restaurant',
         restaurant: 'Pizza da Napoli',
         cuisine: 'pizza'
     })
+]
     
-    Usergrid.POST(entity, function(err, usergridResponse, entity) {
-        entity.owner = 'Mia Carrara'
-        Usergrid.PUT(entity, function(err, usergridResponse, entity) {
-            // entity now has the property 'owner'
-        })
+Usergrid.POST(entities, function(error, usergridResponse, entities) {
+    //
+})
+```
+    
+To update an entity in a collection (PUT request):
+
+```js
+var entity = new UsergridEntity({
+    type: 'restaurant',
+    restaurant: 'Pizza da Napoli',
+    cuisine: 'pizza'
+})
+    
+Usergrid.POST(entity, function(error, usergridResponse, entity) {
+    entity.owner = 'Mia Carrara'
+    Usergrid.PUT(entity, function(error, usergridResponse, entity) {
+        // entity now has the property 'owner'
     })
+})
     
-    // or update a set of entities by passing a UsergridQuery object
+// or update a set of entities by passing a UsergridQuery object
     
-    var query = new UsergridQuery('restaurants')
-                                 .eq('cuisine', 'italian')
-                                 
-    // this will build out the following query:
-    // select * where cuisine = 'italian'
+var query = new UsergridQuery('restaurants')
+                             .eq('cuisine', 'italian')
+                             
+// this will build out the following query:
+// select * where cuisine = 'italian'
     
-    Usergrid.PUT(query, { keywords: ['pasta'] }, function(err, usergridResponse) {
-        /* the first 10 entities matching this query criteria will be updated:
-           e.g.:
-           [
-               {
-                   "type": "restaurant",
-                   "restaurant": "Il Tarazzo",
-                   "cuisine": "italian",
-                   "keywords": [
-                       "pasta"
-                   ]
-               },
-               {
-                   "type": "restaurant",
-                   "restaurant": "Cono Sur Pizza & Pasta",
-                   "cuisine": "italian",
-                   "keywords": [
-                       "pasta"
-                   ]
-               }
-            ]
-        /*
-    })
+Usergrid.PUT(query, { keywords: ['pasta'] }, function(error, usergridResponse) {
+    /* the first 10 entities matching this query criteria will be updated:
+       e.g.:
+       [
+           {
+               "type": "restaurant",
+               "restaurant": "Il Tarazzo",
+               "cuisine": "italian",
+               "keywords": [
+                   "pasta"
+               ]
+           },
+           {
+               "type": "restaurant",
+               "restaurant": "Cono Sur Pizza & Pasta",
+               "cuisine": "italian",
+               "keywords": [
+                   "pasta"
+               ]
+           }
+        ]
+    */
+})
+```
     
-### DELETE requests
+### DELETE()
 
 DELETE requests require either a specific entity or a `UsergridQuery` object to be passed as an argument.
     
-**DELETE a specific entity in a collection by uuid or name**
+To delete a specific entity in a collection by uuid or name:
 
-    Usergrid.DELETE('collection', '<uuid-or-name>', function(err, usergridResponse) {
-        // if successful, entity will now be deleted
-    })
+```js
+Usergrid.DELETE('collection', '<uuid-or-name>', function(error, usergridResponse) {
+    // if successful, entity will now be deleted
+})
+```
     
-**DELETE specific entities in a collection by passing a UsergridQuery object**
+To specific entities in a collection by passing a `UsergridQuery` object:
 
-    var query = new UsergridQuery('cats')
-                                 .eq('color', 'black')
-                                 .or
-                                 .eq('color', 'white')
-                                 
-    // this will build out the following query:
-    // select * where color = 'black' or color = 'white'
+```js
+var query = new UsergridQuery('cats')
+                             .eq('color', 'black')
+                             .or
+                             .eq('color', 'white')
+                             
+// this will build out the following query:
+// select * where color = 'black' or color = 'white'
     
-    Usergrid.DELETE(query, function(err, usergridResponse) {
-        // the first 10 entities matching this query criteria will be deleted
-    })
+Usergrid.DELETE(query, function(error, usergridResponse) {
+    // the first 10 entities matching this query criteria will be deleted
+})
+```
 
 ## Entity operations and convenience methods
 
-`UsergridEntity` has a number of helper/convenience methods to make working with entities more convenient.
+`UsergridEntity` has a number of helper/convenience methods to make working with entities more convenient. If you are _not_ utilizing the `Usergrid` shared instance, you must pass an instance of `UsergridClient` as the first argument to any of these helper methods.
 
-### reload
+### reload()
 
-    entity.reload(function(err, usergridResponse) {
-        // entity is now reloaded from the server
-    })
+Reloads the entity from the server
+
+```js
+entity.reload(function(error, usergridResponse) {
+    // entity is now reloaded from the server
+})
+```
     
-### save
+### save()
 
-    entity.aNewProperty = 'A new value'
-    entity.save(function(err, usergridResponse) {
-        // entity is now updated on the server
-    })
+Saves (or creates) the entity on the server
+
+```js
+entity.aNewProperty = 'A new value'
+entity.save(function(error, usergridResponse) {
+    // entity is now updated on the server
+})
+```
     
-### remove
+### remove()
 
-    entity.remove(function(err, usergridResponse) {
-        // entity is now deleted on the server and the local instance should be destroyed
-    })
+Deletes the entity from the server
 
-## UsergridResponse
+```js
+entity.remove(function(error, usergridResponse) {
+    // entity is now deleted on the server and the local instance should be destroyed
+})
+```
+    
+## Authentication, current user, and auth-fallback
+
+### appAuth and authenticateApp()
+
+`Usergrid` can use the app client ID and secret that were passed upon initialization and automatically retrieve an app-level token for these credentials.
+
+```js
+Usergrid.setAppAuth('<client-id>', '<client-secret>')
+Usergrid.authenticateApp(function(error, usergridResponse, token) {
+    // Usergrid.appAuth is created automatically when this call is successful
+})
+```
+
+### currentUser and authenticateUser()
+
+`Usergrid` has a special `currentUser` property. By default, when calling `authenticateUser()`, `.currentUser` will be set to this user if the authentication flow is successful.
+
+```js
+Usergrid.authenticateUser({
+    username: '<username>',
+    password: '<password>'
+}, function(error, usergridResponse, token) {
+    // Usergrid.currentUser is set to the authenticated user and the token is stored within that context
+})
+```
+    
+If you want to utilize authenticateUser without setting as the current user, simply pass a `false` boolean value as the second parameter:
+
+```js
+Usergrid.authenticateUser({
+    username: '<username>',
+    password: '<password>'
+}, false, function(error, usergridResponse, token) {
+    
+})
+```
+
+### authFallback
+
+Auth-fallback defines what the client should do when a user token is not present. By default, `Usergrid.authFallback` is set to `UsergridAuth.AUTH_FALLBACK_NONE`, whereby when a token is *not* present, an API call will be performed unauthenticated. If instead `Usergrid.authFallback` is set to `UsergridAuth.AUTH_FALLBACK_APP`, the API call will instead be performed using client credentials, _if_ they're available (i.e. `authenticateApp()` was performed at some point). 
+
+### usingAuth()
+
+At times it is desireable to have complete, granular control over the authentication context of an API call. To facilitate this, the passthrough function `.usingAuth()` allows you to pre-define the auth context of the next API call.
+
+```js
+// assume Usergrid.authFallback = UsergridAuth.AUTH_FALLBACK_NONE
+    
+Usergrid.usingAuth(Usergrid.appAuth).POST('roles/guest/permissions', {
+    permission: "get,post,put,delete:/**"
+}, function(error, usergridResponse) {
+    // here we've temporarily used the client credentials to modify permissions
+    // subsequent calls will not use this auth context
+})
+```
+    
+## User operations and convenience methods
+
+`UsergridUser` has a number of helper/convenience methods to make working with user entities more convenient. If you are _not_ utilizing the `Usergrid` shared instance, you must pass an instance of `UsergridClient` as the first argument to any of these helper methods.
+    
+### create()
+
+Creating a new user:
+
+```js
+var user = new UsergridUser({
+    username: 'username',
+    password: 'password'
+})
+    
+user.create(function(error, usergridResponse, user) {
+    // user has now been created and should have a valid uuid
+})
+```
+    
+### login()
+
+A simpler means of retrieving a user-level token:
+
+```js
+var user = new UsergridUser({
+    username: 'username',
+    password: 'password'
+})
+    
+user.login(function(error, usergridResponse, token) {
+    // user is now logged in
+})
+```
+
+### logout()
+
+Logs out the selected user. You can also use this convenience method on `Usergrid.currentUser`.
+
+```js
+user.logout(function(error, usergridResponse) {
+    // user is now logged out
+})
+```
+    
+### logoutAllSessions()
+
+Logs out all sessions for the selected user and destroys all active tokens. You can also use this convenience method on `Usergrid.currentUser`.
+
+```js
+user.logoutAllSessions(function(error, usergridResponse) {
+    // user is now logged out from everywhere
+})
+```
+    
+### resetPassword()
+
+Resets the password for the selected user.
+
+```js
+user.resetPassword({
+    oldPassword: '2cool4u',
+    newPassword: 'correct-horse-battery-staple',
+}, function(error, response, success) {
+    // if it was done correctly, the new password will be changed
+    // 'success' is a boolean value that indicates whether it was changed successfully
+})
+```
+    
+### UsergridUser.CheckAvailable()
+
+This is a class (static) method that allows you to check whether a username or email address is available or not.
+
+```js
+UsergridUser.CheckAvailable(client, {
+    email: 'email'
+}, function(err, response, exists) {
+   // 'exists' is a boolean value that indicates whether a user already exists
+})
+    
+UsergridUser.CheckAvailable(client, {
+    username: 'username'
+}, function(err, response, exists) {
+   
+})
+    
+UsergridUser.CheckAvailable(client, {
+    email: 'email',
+    username: 'username', // checks both email and username
+}, function(err, response, exists) {
+    // 'exists' returns true if either username or email exist
+})
+```
+    
+## Querying and filtering data
+
+### UsergridQuery initialization
+
+The `UsergridQuery` class allows you to build out complex query filters using the Usergrid [query syntax](http://docs.apigee.com/app-services/content/querying-your-data).
+
+The first parameter of the `UsergridQuery` builder pattern should be the collection (or type) you intend to query. You can either pass this as an argument, or as the first builder object:
+
+```js
+var query = new UsergridQuery('cats')
+// or
+var query = new UsergridQuery().type('cats')
+var query = new UsergridQuery().collection('cats')
+```
+
+You then can layer on additional queries:
+
+```js
+var query = new UsergridQuery('cats')
+            .gt('weight', 2.4)
+            .contains('color', 'bl*')
+            .not
+            .eq('color', 'white')
+            .or
+            .eq('color', 'orange') 
+```
+            
+You can also adjust the number of results returned:
+
+```js
+var query = new UsergridQuery('cats').eq('color', 'black').limit(100)
+// returns a maximum of 100 entiteis
+```
+    
+And sort the results:
+
+```js
+var query = new UsergridQuery('cats').eq('color', 'black').asc('name')
+// sorts by 'name', ascending
+```
+    
+And you can do geo-location queries:
+
+```js
+var query = new UsergridQuery('devices').locationWithin(<distanceInMeters>, <latitude>, <longitude>)
+```
+    
+### Using a query in a request
+
+Queries can be passed as parameters to GET, PUT, and DELETE requests:
+
+```js
+Usergrid.GET(query, function(error, usergridResponse, entities) {
+    //
+})
+    
+Usergrid.PUT(query, { aNewProperty: "A new value" }, function(error, usergridResponse, entities) {
+    //
+})
+    
+Usergrid.DELETE(query, function(error, usergridResponse, entities) {
+    //
+})
+```
+    
+While not a typical use case, sometimes it is useful to be able to create a query that works on multiple collections. Therefore, in each one of these RESTful calls, you can optionally pass a 'type' string as the first argument:
+
+```js
+Usergrid.GET('cats', query, function(error, usergridResponse, entities) {
+    //
+})
+```
+    
+### List of query builder objects
+
+`type('string')`
+
+> The collection name to query
+
+`collection('string')`
+
+> An alias for `type`
+
+`eq('key', 'value')` or `equal('key', 'value')`
+
+> Equal to (e.g. `where color = 'black'`)
+
+`contains('key', 'value')`
+
+> Contains a string (e.g.` where color contains 'bl*'`)
+
+`gt('key', 'value')` or `greaterThan('key', 'value')`
+
+> Greater than (e.g. `where weight > 2.4`)
+
+`gte('key', 'value')` or `greaterThanOrEqual('key', 'value')`
+
+> Greater than or equal to (e.g. `where weight >= 2.4`)
+
+`lt('key', 'value')` or `lessThan('key', 'value')`
+
+> Less than (e.g. `where weight < 2.4`)
+
+`lte('key', 'value')` or `lessThanOrEqual('key', 'value')`
+
+> Less than or equal to (e.g. `where weight <= 2.4`)
+
+`not`
+
+> Negates the next block in the builder pattern, e.g.:
+
+```js
+var query = new UsergridQuery('cats').not.eq('color', 'black')
+// select * from cats where not color = 'black'
+```
+
+`and`
+
+> Joins two queries by requiring both of them. `and` is also implied when joining two queries _without_ an operator. E.g.:
+
+```js
+var query = new UsergridQuery('cats').eq('color', 'black').eq('fur', 'longHair')
+// is identical to:
+var query = new UsergridQuery('cats').eq('color', 'black').and.eq('fur', 'longHair')  
+```
+
+`or`
+
+> Joins two queries by requiring only one of them. `or` is never implied. E.g.:
+
+```js
+var query = new UsergridQuery('cats').eq('color', 'black').or.eq('color', 'white')
+```
+    
+> When using `or` and `and` operators, `and` joins will take precedence over `or` joins. You can read more about query operators and precedence [here](http://docs.apigee.com/api-baas/content/supported-query-operators-data-types).
+
+`locationWithin(distanceInMeters, latitude, longitude)`
+
+> Returns entities which have a location within the specified radius. Arguments can be `float` or `int`.
+
+`asc('key')`
+
+> Sorts the results by the specified property, ascending
+
+`desc('key')`
+
+> Sorts the results by the specified property, descending
+
+`sort('key', 'order')`
+
+> Sorts the results by the specified property, in the specified order (`asc` or `desc`).
+ 
+`limit(int)`
+
+> The maximum number of entities to return
+
+`cursor('string')`
+
+> A pagination cursor string
+
+`fromString('query string')`
+
+> A special builder property that allows you to input a pre-defined query string. All other builder properties will be ignored when this property is defined. For example:
+    
+```js
+var query = new UsergridQuery().fromString("select * where color = 'black' order by name asc")
+```
+
+## UsergridResponse object
 
 `UsergridResponse` implements several Usergrid-specific enhancements to [request](https://github.com/request/request). Notably:
 
@@ -251,11 +601,13 @@
 
 You can check `usergridResponse.ok`, a `bool` value, to see if the response was successful. Any status code < 400 returns true.
 
-    Usergrid.GET('collection', function(err, usergridResponse, entities) {
-        if (usergridResponse.ok) {
-            // woo!
-        }
-    })
+```js
+Usergrid.GET('collection', function(error, usergridResponse, entities) {
+    if (usergridResponse.ok) {
+        // woo!
+    }
+})
+```
     
 ### entity, entities, user, users, first, last
 
@@ -269,36 +621,81 @@
 
 Examples:
 
-    Usergrid.GET('collection', function(err, usergridResponse, entities) {
-        // third param is an array of entities because no specific entity was referenced
-        // you can also access:
-        //     usergridResponse.entities
-        //     usergridResponse.first    
-        //     usergridResponse.entity (the first entity)      
-        //     usergridResponse.last		 
-    })
+```js
+Usergrid.GET('collection', function(error, usergridResponse, entities) {
+    // third param is an array of entities because no specific entity was referenced
+    // you can also access:
+    //     usergridResponse.entities
+    //     usergridResponse.first    
+    //     usergridResponse.entity (the first entity)      
+    //     usergridResponse.last		 
+})
     
-    Usergrid.GET('collection', '<uuid or name>', function(err, usergridResponse, entity) {
-        // third param is a single entity object
-        // you can also access:
-        //     usergridResponse.entity
-        //     usergridResponse.first  
-        //     usergridResponse.last                
-    })
+Usergrid.GET('collection', '<uuid or name>', function(error, usergridResponse, entity) {
+    // third param is a single entity object
+    // you can also access:
+    //     usergridResponse.entity
+    //     usergridResponse.first  
+    //     usergridResponse.last                
+})
     
-    Usergrid.GET('users', function(err, usergridResponse, users) {
-        // third param is an array of users because no specific user was referenced
-        // you can also access:
-        //     usergridResponse.users
-        //     usergridResponse.user (the first user)          
-        //     usergridResponse.last 
-    })
+Usergrid.GET('users', function(error, usergridResponse, users) {
+    // third param is an array of users because no specific user was referenced
+    // you can also access:
+    //     usergridResponse.users
+    //     usergridResponse.user (the first user)          
+    //     usergridResponse.last 
+})
     
-    Usergrid.GET('users', '<uuid, username, or email>', function(err, usergridResponse, user) {
-        // third param is a single user object
-        // you can also access:
-        //     usergridResponse.user
-    })
+Usergrid.GET('users', '<uuid, username, or email>', function(error, usergridResponse, user) {
+    // third param is a single user object
+    // you can also access:
+    //     usergridResponse.user
+})
+```
+    
+## Connections
+
+Connections can be managed using `Usergrid.connect()`, `Usergrid.disconnect()`, and `Usergrid.getConnections()`, or entity convenience methods of the same name.
+
+### connect
+
+Create a connection between two entities:
+
+```js
+Usergrid.connect(entity1, 'relationship', entity2, function(error, usergridResponse) {
+    // entity1 now has an outbound connection to entity2
+})
+```
+    
+### getConnections
+
+Retrieve outbound connections:
+
+```js
+client.getConnections(UsergridClient.Connections.DIRECTION_OUT, entity1, 'relationship', function(error, usergridResponse, entities) {
+    // entities is an array of entities that entity1 is connected to via 'relationship'
+    // in this case, we'll see entity2 in the array
+})
+```
+    
+Retrieve inbound connections:
+
+```js
+client.getConnections(UsergridClient.Connections.DIRECTION_IN, entity2, 'relationship', function(error, usergridResponse, entities) {
+    // entities is an array of entities that connect to entity2 via 'relationship'
+    // in this case, we'll see entity1 in the array
+})```
+    
+### disconnect
+
+Delete a connection between two entities:
+
+```js
+Usergrid.disconnect(entity1, 'relationship', entity2, function(error, usergridResponse) {
+    // entity1's outbound connection to entity2 has been destroyed
+})
+```
     
 ## Assets
 
@@ -306,59 +703,70 @@
 
 ### UsergridAsset init
 
-**Loading a file system image via `fs.readFile()`**
+Loading a file system image via `fs.readFile()`:
 
-    var asset = new UsergridAsset('myImage')
-    fs.readFile(_dirname + '/image.jpg', function(err, data) {
-        asset.data = data
-    })
+```js
+var asset = new UsergridAsset('myImage')
+fs.readFile(_dirname + '/image.jpg', function(error, data) {
+    asset.data = data
+})
+```
     
-**Loading a file system image from a read stream (`fs.createReadStream()`)**
+Loading a file system image from a read stream (`fs.createReadStream()`):
 
-    var asset = new UsergridAsset('myImage')
-    fs.createReadStream(_dirname + '/image.jpg').pipe(asset).on('finish', function() {
-        // now contains Buffer stream at asset.data
-    })
+```js
+var asset = new UsergridAsset('myImage')
+fs.createReadStream(_dirname + '/image.jpg').pipe(asset).on('finish', function() {
+    // now contains Buffer stream at asset.data
+})
+```
     
 You can also access `asset.contentType` and `asset.contentLength` once data has been loaded into a `UsergridAsset`.
 
 ### .POST and .PUT
 
-**POST binary data to a collection by creating a new entity**
+POST binary data to a collection by creating a new entity:
 
-    var asset = new UsergridAsset('myImage')
-    fs.createReadStream(_dirname + '/image.jpg').pipe(asset).on('finish', function() {
-        client.POST('collection', asset, function(err, assetResponse, entityWithAsset) {
-            // asset is now uploaded to Usergrid
-        })
+```js
+var asset = new UsergridAsset('myImage')
+fs.createReadStream(_dirname + '/image.jpg').pipe(asset).on('finish', function() {
+    client.POST('collection', asset, function(error, assetResponse, entityWithAsset) {
+        // asset is now uploaded to Usergrid
     })
+})
+```
 
-**PUT binary data to an existing entity via attachAsset()**
+PUT binary data to an existing entity via attachAsset():
     
-    var asset = new UsergridAsset('myImage')
-    fs.createReadStream(_dirname + '/image.jpg').pipe(asset).on('finish', function() {
-        // assume entity already exists; attach it to the entity:
-        entity.attachAsset(asset)
-        client.PUT(entity, asset, function(err, assetResponse, entityWithAsset) {
-            // asset is now uploaded to Usergrid
-        })
+```js
+var asset = new UsergridAsset('myImage')
+fs.createReadStream(_dirname + '/image.jpg').pipe(asset).on('finish', function() {
+    // assume entity already exists; attach it to the entity:
+    entity.attachAsset(asset)
+    client.PUT(entity, asset, function(error, assetResponse, entityWithAsset) {
+        // asset is now uploaded to Usergrid
     })
+})
+```
     
 ### UsergridEntity convenience methods
 
-**entity.uploadAsset() is a much simpler means of uploading an asset**
+`entity.uploadAsset()` is a convenient way to upload an asset that is attached to an entity:
 
-    var asset = new UsergridAsset('myImage')
-    fs.createReadStream(_dirname + '/image.jpg').pipe(asset).on('finish', function() {
-        // assume entity already exists; attach it to the entity:
-        entity.attachAsset(asset)
-        entity.uploadAsset(function(err, assetResponse, entityWithAsset) {
-            // asset is now uploaded to Usergrid
-        })
+```js
+var asset = new UsergridAsset('myImage')
+fs.createReadStream(_dirname + '/image.jpg').pipe(asset).on('finish', function() {
+    // assume entity already exists; attach it to the entity:
+    entity.attachAsset(asset)
+    entity.uploadAsset(function(error, assetResponse, entityWithAsset) {
+        // asset is now uploaded to Usergrid
     })
+})
+```
     
-**entity.downloadAsset() allows you to download a binary asset**
+`entity.downloadAsset()` allows you to download a binary asset:
 
-    entity.uploadAsset(function(err, assetResponse, entityWithAsset) {
-        // access the asset via entityWithAsset.asset
-    })
+```js
+entity.uploadAsset(function(error, assetResponse, entityWithAsset) {
+    // access the asset via entityWithAsset.asset
+})```
diff --git a/examples/api-proxy/README.md b/examples/api-proxy/README.md
new file mode 100644
index 0000000..db03d0a
--- /dev/null
+++ b/examples/api-proxy/README.md
@@ -0,0 +1,4 @@
+To use this example, rename the `usergrid.example.json` to `usergrid.json`.  
+This file is located at `examples/api-proxy/config`.
+
+**Note:** The usergrid module crawls your App file structure to find files named `usergrid.json` or a `config.json`.  If there are multiple files with one of these names present at different locations under the app, only one of them will be used and the others are ignored.  This may cause use of an unintended backend.  
diff --git a/examples/api-proxy/app.js b/examples/api-proxy/app.js
new file mode 100644
index 0000000..76b3401
--- /dev/null
+++ b/examples/api-proxy/app.js
@@ -0,0 +1,30 @@
+var express = require('express'),
+    app = express(),
+    Usergrid = require('usergrid'),
+    async = require('async'),
+    chance = require('chance')
+
+Usergrid.init()
+
+// Usergrid.setAppAuth(id, secret)
+// console.log(Usergrid.appAuth)
+Usergrid.authenticateApp(function(err, usergridResponse) {
+    if (usergridResponse.ok) {
+        console.log('app is now authenticated')
+    }
+})
+
+app.get('/:collection/:uuidOrName?', function(req, res) {
+    Usergrid.GET(req.params.collection, req.params.uuidOrName, function(error, usergridResponse, entities) {
+        res.json(entities);
+    })
+})
+
+// app.listen(process.env.port || 9000)
+
+/*
+
+1. Start the server using > node app.js
+2. Call the api at http://localhost:9000/cats/test
+
+*/
\ No newline at end of file
diff --git a/examples/api-proxy/config/usergrid.example.json b/examples/api-proxy/config/usergrid.example.json
new file mode 100644
index 0000000..5d13860
--- /dev/null
+++ b/examples/api-proxy/config/usergrid.example.json
@@ -0,0 +1,8 @@
+{
+    "appId": "sandbox",
+    "orgId": "brandon.apigee",
+    "authFallback": "NONE",
+    "baseUrl": "https://api.usergrid.com",
+    "clientId": "YXA6GXSAACS2EeOYd20aP4G6Lw",
+    "clientSecret": "YXA66BeEvgNpJBwc4PAbvZZGTVS_SSw"
+}
\ No newline at end of file
diff --git a/examples/api-proxy/package.json b/examples/api-proxy/package.json
new file mode 100644
index 0000000..53deec5
--- /dev/null
+++ b/examples/api-proxy/package.json
@@ -0,0 +1,19 @@
+{
+    "dependencies": {
+        "async": "latest",
+        "express": "latest",
+        "usergrid": "r3mus/usergrid-nodejs",
+        "chance": "^0.8.0"
+    },
+    "description": "A sample API proxy built with Express and Usergrid",
+    "keywords": [],
+    "license": "MIT",
+    "main": "app.js",
+    "name": "usergrid-example-api-proxy",
+    "private": false,
+    "scripts": {
+        "start": "node app.js",
+        "test": "mocha tests"
+    },
+    "version": "2.0.0-rc.1"
+}
\ No newline at end of file
diff --git a/helpers/args.js b/helpers/args.js
index ecef57b..6f221a5 100644
--- a/helpers/args.js
+++ b/helpers/args.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var _ = require('lodash')
diff --git a/helpers/build.js b/helpers/build.js
index 88656a1..3697fee 100644
--- a/helpers/build.js
+++ b/helpers/build.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var urljoin = require('url-join'),
diff --git a/helpers/cb.js b/helpers/cb.js
index 8c62591..109ef27 100644
--- a/helpers/cb.js
+++ b/helpers/cb.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var ok = require('objectkit'),
diff --git a/helpers/client.js b/helpers/client.js
index e506b88..ccea0d5 100644
--- a/helpers/client.js
+++ b/helpers/client.js
@@ -1,14 +1,27 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
-var UsergridClient = require('../lib/client'),
-    UsergridAuth = require('../lib/auth'),
-    Usergrid = require('../usergrid'),
+var Usergrid = require('../usergrid'),
     helpers = require('../helpers'),
     _ = require('lodash')
 
 
 module.exports = {
     validate: function(args) {
+        var UsergridClient = require('../lib/client')
         var client
         if (args instanceof UsergridClient) {
             client = args
@@ -22,6 +35,7 @@
         return client
     },
     configureTempAuth: function(auth) {
+        var UsergridAuth = require('../lib/auth')
         if (_.isString(auth) && auth !== UsergridAuth.NO_AUTH) {
             return new UsergridAuth(auth)
         } else if (!auth || auth === UsergridAuth.NO_AUTH) {
diff --git a/helpers/config.js b/helpers/config.js
index 26c4fd2..50af670 100644
--- a/helpers/config.js
+++ b/helpers/config.js
@@ -1,7 +1,24 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var util = require('util'),
-    _ = require('lodash')
+    path = require('path'),
+    file = require("file"),
+    _ = require('lodash'),
+    appRoot = path.dirname(require.main.filename)
 
 if (/mocha$/i.test(process.argv[1])) {
     var target = _(_.last(process.argv)).startsWith('--target=') ? _.last(process.argv).replace(/--target=/, '') : '1.0'
@@ -14,8 +31,22 @@
     module.exports = config
 } else {
     try {
-        module.exports = require('../config.json')
+        file.walkSync(appRoot, function(start, dirs, names) {
+            if (_.includes(names, "config.json") || _.includes(names, "usergrid.json")) {
+                var name = _.first(names.filter(function(name) {
+                    return name == "config.json" || name == "usergrid.json"
+                }).sort().reverse())
+                var configPath = util.format("%s/%s", start, name)
+                module.exports = require(configPath)
+                if (module.exports.orgId === undefined || module.exports.appId === undefined) {
+                    console.log(util.format("Config file '%s' is not a valid Usergrid configuration file", configPath))
+                    module.exports = {}
+                } else {
+                    console.log(util.format("Using config file '%s'", configPath))
+                }
+            }
+        })
     } catch (e) {
-        
+
     }
 }
\ No newline at end of file
diff --git a/helpers/index.js b/helpers/index.js
index 954e353..6a46b6d 100644
--- a/helpers/index.js
+++ b/helpers/index.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var args = require('./args'),
diff --git a/helpers/mutability.js b/helpers/mutability.js
index 1762264..b948d2b 100644
--- a/helpers/mutability.js
+++ b/helpers/mutability.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var ok = require('objectkit'),
diff --git a/helpers/query.js b/helpers/query.js
index c0f4394..f019545 100644
--- a/helpers/query.js
+++ b/helpers/query.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var util = require('util'),
diff --git a/helpers/time.js b/helpers/time.js
index 06e8d84..d3452b1 100644
--- a/helpers/time.js
+++ b/helpers/time.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 module.exports = {
diff --git a/helpers/user.js b/helpers/user.js
index 470cf06..45dcde4 100644
--- a/helpers/user.js
+++ b/helpers/user.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var _ = require('lodash')
diff --git a/lib/appAuth.js b/lib/appAuth.js
index 157db3e..740002e 100644
--- a/lib/appAuth.js
+++ b/lib/appAuth.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var UsergridAuth = require('./auth'),
@@ -5,15 +19,18 @@
     util = require('util'),
     _ = require('lodash')
 
-var UsergridAppAuth = function(options) {
+var UsergridAppAuth = function() {
     var self = this
     var args = _.flattenDeep(helpers.args(arguments))
     if (_.isPlainObject(args[0])) {
-        options = args[0]
+        self.clientId = args[0].clientId
+        self.clientSecret = args[0].clientSecret
+        self.tokenTtl = args[0].tokenTtl
+    } else {
+        self.clientId = args[0]
+        self.clientSecret = args[1]
+        self.tokenTtl = args[2]
     }
-    self.clientId = options.clientId || args[0]
-    self.clientSecret = options.clientSecret || args[1]
-    self.tokenTtl = options.tokenTtl || args[2]
     UsergridAuth.call(self)
     _.assign(self, UsergridAuth)
     return self
diff --git a/lib/asset.js b/lib/asset.js
index 5d9799a..681db0c 100644
--- a/lib/asset.js
+++ b/lib/asset.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var Usergrid = require('../usergrid'),
diff --git a/lib/auth.js b/lib/auth.js
index 2422d30..d3872d8 100644
--- a/lib/auth.js
+++ b/lib/auth.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var UsergridAuth = function(token, expiry) {
diff --git a/lib/client.js b/lib/client.js
index c337484..f022793 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var helpers = require('../helpers'),
@@ -32,6 +46,18 @@
         throw new Error('"orgId" and "appId" parameters are required when instantiating UsergridClient')
     }
 
+    Object.defineProperty(self, 'test', {
+        enumerable: false
+    })
+
+    Object.defineProperty(self, 'clientId', {
+        enumerable: false
+    })
+
+    Object.defineProperty(self, 'clientSecret', {
+        enumerable: false
+    })
+
     Object.defineProperty(self, 'appAuth', {
         get: function() {
             return __appAuth
@@ -45,10 +71,10 @@
         }
     })
 
-    Object.defineProperty(self, 'test', {
-        enumerable: false
-    })
-
+    // if client ID and secret are defined on initialization, initialize appAuth
+    if (self.clientId && self.clientSecret) {
+        self.setAppAuth(self.clientId, self.clientSecret)
+    }
     return self
 }
 
@@ -74,13 +100,16 @@
     getConnections: function() {        
         return new UsergridRequest(helpers.build.getConnections(this, helpers.args(arguments)))
     },
-    setAppAuth: function(options) {
-        this.appAuth = (_.isString(options)) ? helpers.args(arguments) : options
+    setAppAuth: function() {
+        this.appAuth = new UsergridAppAuth(helpers.args(arguments))
     },
     authenticateApp: function(options) {
         var self = this
         var callback = helpers.cb(helpers.args(arguments))
-        var auth = (options instanceof UsergridAppAuth) ? options : self.appAuth || new UsergridAppAuth(options)
+        console.log(self.appAuth)//, self.appAuth, new UsergridAppAuth(options), new UsergridAppAuth(self.clientId, self.clientSecret))
+        var auth = _.first([options, self.appAuth, new UsergridAppAuth(options), new UsergridAppAuth(self.clientId, self.clientSecret)].filter(function(p) {
+            return p instanceof UsergridAppAuth
+        }))
 
         if (!(auth instanceof UsergridAppAuth)) {
             throw new Error('App auth context was not defined when attempting to call .authenticateApp()')
@@ -107,12 +136,13 @@
     },
     authenticateUser: function(options) {
         var self = this
-        var callback = helpers.cb(helpers.args(arguments))
-
+        var args = helpers.args(arguments)
+        var callback = helpers.cb(args)
+        var setAsCurrentUser = (_.last(args.filter(_.isBoolean))) !== undefined ? _.last(args.filter(_.isBoolean)) : true
         var UsergridUser = require('./user')
         var currentUser = new UsergridUser(options)
         currentUser.login(self, function(error, usergridResponse, token) {
-            if (usergridResponse.ok) {
+            if (usergridResponse.ok && setAsCurrentUser) {
                 self.currentUser = currentUser
             }
             callback(error, usergridResponse, token)
diff --git a/lib/entity.js b/lib/entity.js
index fe35d58..eda1086 100644
--- a/lib/entity.js
+++ b/lib/entity.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var Usergrid = require('../usergrid'),
diff --git a/lib/query.js b/lib/query.js
index a819108..87daf7d 100644
--- a/lib/query.js
+++ b/lib/query.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var helpers = require('../helpers'),
diff --git a/lib/request.js b/lib/request.js
index 3a4b1c3..70bb851 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var request = require('request'),
diff --git a/lib/response.js b/lib/response.js
index fade45c..b2f6fd4 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var ok = require('objectkit'),
diff --git a/lib/responseError.js b/lib/responseError.js
index 1de62b9..38df35c 100644
--- a/lib/responseError.js
+++ b/lib/responseError.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var ok = require('objectkit')
diff --git a/lib/user.js b/lib/user.js
index 6743575..e9e6d15 100644
--- a/lib/user.js
+++ b/lib/user.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var UsergridEntity = require('./entity'),
diff --git a/lib/userAuth.js b/lib/userAuth.js
index e6fa8ff..5c61e5c 100644
--- a/lib/userAuth.js
+++ b/lib/userAuth.js
@@ -1,3 +1,17 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
 var UsergridAuth = require('./auth'),
diff --git a/package.json b/package.json
index 4c93a88..a07c150 100644
--- a/package.json
+++ b/package.json
@@ -2,6 +2,7 @@
   "author": "Brandon Shelley",
   "dependencies": {
     "async": "latest",
+    "file": "latest",
     "file-type": "^3.4.0",
     "lodash": "~4.0",
     "lodash-inflection": "latest",
@@ -23,13 +24,13 @@
     "url": "git://github.com/r3mus/usergrid-nodejs.git"
   },
   "keywords": [],
-  "license": "MIT",
-  "main": "app.js",
+  "license": "Apache 2.0",
+  "main": "usergrid.js",
   "name": "usergrid",
   "private": false,
   "scripts": {
-    "start": "node app.js",
+    "start": "node usergrid.js",
     "test": "mocha tests"
   },
-  "version": "2.0.0-rc.0"
+  "version": "2.0.0-rc.1"
 }
diff --git a/tests/lib/client.auth.test.js b/tests/lib/client.auth.test.js
index c7f6bad..ad33987 100644
--- a/tests/lib/client.auth.test.js
+++ b/tests/lib/client.auth.test.js
@@ -202,8 +202,8 @@
 
     it('should fail when called without a email (or username) and password', function() {
         should(function() {
-            var client = new UsergridClient()
-            client.authenticateUser({})
+            var badClient = new UsergridClient()
+            badClient.authenticateUser({})
         }).throw()
     })
 
@@ -238,6 +238,18 @@
         client.currentUser.auth.should.not.have.property('password')
     })
 
+    it('should support an optional bool to not set as current user', function(done) {
+        var noCurrentUserClient = new UsergridClient()
+        noCurrentUserClient.authenticateUser({
+            username: config.test.username,
+            password: config.test.password,
+            email: email
+        }, false, function(err, r, t) {
+            should(noCurrentUserClient.currentUser).be.undefined()
+            done()
+        })
+    })
+
     it('should support passing a UsergridUserAuth instance with a custom ttl', function(done) {
         var newClient = new UsergridClient()
         var ttlInMilliseconds = 500000
diff --git a/usergrid.js b/usergrid.js
index d4fe3cd..cc6ba27 100644
--- a/usergrid.js
+++ b/usergrid.js
@@ -1,16 +1,33 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 'use strict'
 
+var _ = require('lodash')
+
 var Usergrid = {
     isInitialized: false,
     isSharedInstance: true,
     initSharedInstance: function(options) {
         var self = this
         if (self.isInitialized) {
+            console.log('Usergrid shared instance is already initialized')
             return self
         }
         var UsergridClient = require('./lib/client')
-        Object.setPrototypeOf(Usergrid, new UsergridClient(options))
-        UsergridClient.call(self)
+        Object.setPrototypeOf(self, new UsergridClient(options))
+        _.assign(self, new UsergridClient(options))
         self.isInitialized = true
         self.isSharedInstance = true
     }