 			}
 			if (Len(arguments.include))
 			{
-				loc.distinct = true;
-			}
-			else
-			{
-				loc.distinct = false;
+				local.distinct = true;
+			}
+			else
+			{
+				local.distinct = false;
 			}
 			if (arguments.count > 0)
 			{
-				loc.totalRecords = arguments.count;
-			}
-			else
-			{
-				loc.totalRecords = this.count(where=arguments.where, include=arguments.include, reload=arguments.reload, cache=arguments.cache, distinct=loc.distinct, parameterize=arguments.parameterize, includeSoftDeletes=arguments.includeSoftDeletes);
-			}
-			loc.currentPage = arguments.page;
-			if (loc.totalRecords == 0)
-			{
-				loc.totalPages = 0;
-				loc.rv = "";
-			}
-			else
-			{
-				loc.totalPages = Ceiling(loc.totalRecords/arguments.perPage);
-				loc.limit = arguments.perPage;
-				loc.offset = (arguments.perPage * arguments.page) - arguments.perPage;
+				local.totalRecords = arguments.count;
+			}
+			else
+			{
+				local.totalRecords = this.count(where=arguments.where, include=arguments.include, reload=arguments.reload, cache=arguments.cache, distinct=local.distinct, parameterize=arguments.parameterize, includeSoftDeletes=arguments.includeSoftDeletes);
+			}
+			local.currentPage = arguments.page;
+			if (local.totalRecords == 0)
+			{
+				local.totalPages = 0;
+				local.rv = "";
+			}
+			else
+			{
+				local.totalPages = Ceiling(local.totalRecords/arguments.perPage);
+				local.limit = arguments.perPage;
+				local.offset = (arguments.perPage * arguments.page) - arguments.perPage;
 
 				// if the full range of records is not requested we correct the limit to get the exact amount instead
 				// for example if totalRecords is 57, limit is 10 and offset 50 (i.e. requesting records 51-60) we change the limit to 7
-				if ((loc.limit + loc.offset) > loc.totalRecords)
-				{
-					loc.limit = loc.totalRecords - loc.offset;
-				}
-
-				if (loc.limit < 1)
+				if ((local.limit + local.offset) > local.totalRecords)
+				{
+					local.limit = local.totalRecords - local.offset;
+				}
+
+				if (local.limit < 1)
 				{
 					// if limit is 0 or less it means that a page that has no records was asked for so we return an empty query
-					loc.rv = "";
+					local.rv = "";
 				}
 				else
 				{
-					loc.values = findAll($limit=loc.limit, $offset=loc.offset, select=primaryKeys(), where=arguments.where, order=arguments.order, include=arguments.include, reload=arguments.reload, cache=arguments.cache, distinct=loc.distinct, parameterize=arguments.parameterize, includeSoftDeletes=arguments.includeSoftDeletes, callbacks=false);
-					if (loc.values.RecordCount)
+					local.values = findAll($limit=local.limit, $offset=local.offset, select=primaryKeys(), where=arguments.where, order=arguments.order, include=arguments.include, reload=arguments.reload, cache=arguments.cache, distinct=local.distinct, parameterize=arguments.parameterize, includeSoftDeletes=arguments.includeSoftDeletes, callbacks=false);
+					if (local.values.RecordCount)
 					{
-						loc.paginationWhere = "";
-						loc.iEnd = loc.values.recordCount;
-						for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
+						local.paginationWhere = "";
+						local.iEnd = local.values.recordCount;
+						for (local.i=1; local.i <= local.iEnd; local.i++)
 						{
-							loc.keyComboValues = [];
-							loc.jEnd = ListLen(primaryKeys());
-							for (loc.j=1; loc.j <= loc.jEnd; loc.j++)
+							local.keyComboValues = [];
+							local.jEnd = ListLen(primaryKeys());
+							for (local.j=1; local.j <= local.jEnd; local.j++)
 							{
-								loc.property = primaryKeys(loc.j);
-								ArrayAppend(loc.keyComboValues, "#tableName()#.#loc.property# = #variables.wheels.class.adapter.$quoteValue(str=loc.values[loc.property][loc.i], type=validationTypeForProperty(loc.property))#");
+								local.property = primaryKeys(local.j);
+								ArrayAppend(local.keyComboValues, "#tableName()#.#local.property# = #variables.wheels.class.adapter.$quoteValue(str=local.values[local.property][local.i], type=validationTypeForProperty(local.property))#");
 							}
-							loc.paginationWhere = ListAppend(loc.paginationWhere, "(" & ArrayToList(loc.keyComboValues, " AND ") & ")", Chr(7));
+							local.paginationWhere = ListAppend(local.paginationWhere, "(" & ArrayToList(local.keyComboValues, " AND ") & ")", Chr(7));
  						}
-						loc.paginationWhere = Replace(loc.paginationWhere, Chr(7), " OR ", "all");
+						local.paginationWhere = Replace(local.paginationWhere, Chr(7), " OR ", "all");
 
  						// this can be improved to also check if the where clause checks on a joined table, if not we can use the simple where clause with just the ids
  						if (Len(arguments.where) && Len(arguments.include))
  						{
- 							arguments.where = "(#arguments.where#) AND (#loc.paginationWhere#)";
+ 							arguments.where = "(#arguments.where#) AND (#local.paginationWhere#)";
  						}
  						else
 						{
-							arguments.where = loc.paginationWhere;
+							arguments.where = local.paginationWhere;
 						}
 					}
 				}
 			}
 			// store pagination info in the request scope so all pagination methods can access it
-			setPagination(loc.totalRecords, loc.currentPage, arguments.perPage, arguments.handle);
-		}
-
-		if (StructKeyExists(loc, "rv") && !Len(loc.rv))
+			setPagination(local.totalRecords, local.currentPage, arguments.perPage, arguments.handle);
+		}
+
+		if (StructKeyExists(local, "rv") && !Len(local.rv))
 		{
 			if (arguments.returnAs == "query")
 			{
-				loc.rv = QueryNew("");
+				local.rv = QueryNew("");
 			}
 			else if (singularize(arguments.returnAs) == arguments.returnAs)
 			{
-				loc.rv = false;
-			}
-			else
-			{
-				loc.rv = ArrayNew(1);
-			}
-		}
-		else if (!StructKeyExists(loc, "rv"))
+				local.rv = false;
+			}
+			else
+			{
+				local.rv = ArrayNew(1);
+			}
+		}
+		else if (!StructKeyExists(local, "rv"))
 		{
 			// make the where clause generic for use in caching
-			loc.originalWhere = arguments.where;
+			local.originalWhere = arguments.where;
 			arguments.where = REReplace(arguments.where, variables.wheels.class.RESQLWhere, "\1?\8" , "all");
 
 			// get info from cache when available, otherwise create the generic select, from, where and order by clause
-			loc.queryShellKey = $hashedKey(variables.wheels.class.modelName, arguments);
-			loc.sql = $getFromCache(loc.queryShellKey, "sql");
-			if (!IsArray(loc.sql))
-			{
-				loc.sql = [];
-				ArrayAppend(loc.sql, $selectClause(select=arguments.select, include=arguments.include, includeSoftDeletes=arguments.includeSoftDeletes, returnAs=arguments.returnAs));
-				ArrayAppend(loc.sql, $fromClause(include=arguments.include, includeSoftDeletes=arguments.includeSoftDeletes));
-				loc.sql = $addWhereClause(sql=loc.sql, where=loc.originalWhere, include=arguments.include, includeSoftDeletes=arguments.includeSoftDeletes);
-				loc.groupBy = $groupByClause(select=arguments.select, group=arguments.group, include=arguments.include, distinct=arguments.distinct, returnAs=arguments.returnAs);
-				if (Len(loc.groupBy))
-				{
-					ArrayAppend(loc.sql, loc.groupBy);
-				}
-				loc.orderBy = $orderByClause(order=arguments.order, include=arguments.include);
-				if (Len(loc.orderBy))
-				{
-					ArrayAppend(loc.sql, loc.orderBy);
-				}
-				$addToCache(key=loc.queryShellKey, value=loc.sql, category="sql");
+			local.queryShellKey = $hashedKey(variables.wheels.class.modelName, arguments);
+			local.sql = $getFromCache(local.queryShellKey, "sql");
+			if (!IsArray(local.sql))
+			{
+				local.sql = [];
+				ArrayAppend(local.sql, $selectClause(select=arguments.select, include=arguments.include, includeSoftDeletes=arguments.includeSoftDeletes, returnAs=arguments.returnAs));
+				ArrayAppend(local.sql, $fromClause(include=arguments.include, includeSoftDeletes=arguments.includeSoftDeletes));
+				local.sql = $addWhereClause(sql=local.sql, where=local.originalWhere, include=arguments.include, includeSoftDeletes=arguments.includeSoftDeletes);
+				local.groupBy = $groupByClause(select=arguments.select, group=arguments.group, include=arguments.include, distinct=arguments.distinct, returnAs=arguments.returnAs);
+				if (Len(local.groupBy))
+				{
+					ArrayAppend(local.sql, local.groupBy);
+				}
+				local.orderBy = $orderByClause(order=arguments.order, include=arguments.include);
+				if (Len(local.orderBy))
+				{
+					ArrayAppend(local.sql, local.orderBy);
+				}
+				$addToCache(key=local.queryShellKey, value=local.sql, category="sql");
 			}
 
 			// add where clause parameters to the generic sql info
-			loc.sql = $addWhereClauseParameters(sql=loc.sql, where=loc.originalWhere);
+			local.sql = $addWhereClauseParameters(sql=local.sql, where=local.originalWhere);
 
 			// return existing query result if it has been run already in current request, otherwise pass off the sql array to the query
-			loc.queryKey = $hashedKey(variables.wheels.class.modelName, arguments, loc.originalWhere);
-			if (application.wheels.cacheQueriesDuringRequest && !arguments.reload && StructKeyExists(request.wheels, loc.queryKey))
-			{
-				loc.findAll = request.wheels[loc.queryKey];
-			}
-			else
-			{
-				loc.finderArgs = {};
-				loc.finderArgs.sql = loc.sql;
-				loc.finderArgs.maxRows = arguments.maxRows;
-				loc.finderArgs.parameterize = arguments.parameterize;
-				loc.finderArgs.limit = arguments.$limit;
-				loc.finderArgs.offset = arguments.$offset;
-				loc.finderArgs.$primaryKey = primaryKeys();
+			local.queryKey = $hashedKey(variables.wheels.class.modelName, arguments, local.originalWhere);
+			if (application.wheels.cacheQueriesDuringRequest && !arguments.reload && StructKeyExists(request.wheels, local.queryKey))
+			{
+				local.findAll = request.wheels[local.queryKey];
+			}
+			else
+			{
+				local.finderArgs = {};
+				local.finderArgs.sql = local.sql;
+				local.finderArgs.maxRows = arguments.maxRows;
+				local.finderArgs.parameterize = arguments.parameterize;
+				local.finderArgs.limit = arguments.$limit;
+				local.finderArgs.offset = arguments.$offset;
+				local.finderArgs.$primaryKey = primaryKeys();
 				if (application.wheels.cacheQueries && (IsNumeric(arguments.cache) || (IsBoolean(arguments.cache) && arguments.cache)))
 				{
-					loc.finderArgs.cachedWithin = $timeSpanForCache(arguments.cache);
-				}
-				loc.findAll = variables.wheels.class.adapter.$query(argumentCollection=loc.finderArgs);
-				request.wheels[loc.queryKey] = loc.findAll; // <- store in request cache so we never run the exact same query twice in the same request
-			}
-			request.wheels[$hashedKey(loc.findAll.query)] = variables.wheels.class.modelName; // place an identifer in request scope so we can reference this query when passed in to view functions
+					local.finderArgs.cachedWithin = $timeSpanForCache(arguments.cache);
+				}
+				local.findAll = variables.wheels.class.adapter.$query(argumentCollection=local.finderArgs);
+				request.wheels[local.queryKey] = local.findAll; // <- store in request cache so we never run the exact same query twice in the same request
+			}
+			request.wheels[$hashedKey(local.findAll.query)] = variables.wheels.class.modelName; // place an identifer in request scope so we can reference this query when passed in to view functions
 
 			switch (arguments.returnAs)
 			{
 				case "query":
-					loc.rv = loc.findAll.query;
+					local.rv = local.findAll.query;
 
 					// execute callbacks unless we're currently running the count or primary key pagination queries (we only want the callback to run when we have the actual data)
-					if (loc.rv.columnList != "wheelsqueryresult" && !arguments.$limit && !arguments.$offset)
+					if (local.rv.columnList != "wheelsqueryresult" && !arguments.$limit && !arguments.$offset)
 					{
-						$callback("afterFind", arguments.callbacks, loc.rv);
+						$callback("afterFind", arguments.callbacks, local.rv);
 					}
 					break;
 				case "struct": case "structs":
-					loc.rv = $serializeQueryToStructs(query=loc.findAll.query, argumentCollection=arguments);
+					local.rv = $serializeQueryToStructs(query=local.findAll.query, argumentCollection=arguments);
 					break;
 				case "object": case "objects":
-					loc.rv = $serializeQueryToObjects(query=loc.findAll.query, argumentCollection=arguments);
+					local.rv = $serializeQueryToObjects(query=local.findAll.query, argumentCollection=arguments);
 					break;
 				default:
 					if (application.wheels.showErrorInformation)

						$throw(type="Wheels.IncorrectArgumentValue", message="Incorrect Arguments", extendedInfo="The `returnAs` may be either `query`, `struct(s)` or `object(s)`");
					}
			}
		}
	</cfscript>
	<cfreturn loc.rv>
</cffunction>

<cffunction name="findByKey" returntype="any" access="public" output="false">
	<cfargument name="key" type="any" required="true">
	<cfargument name="select" type="string" required="false" default="">
	<cfargument name="include" type="string" required="false" default="">
	<cfargument name="cache" type="any" required="false" default="">
	<cfargument name="reload" type="boolean" required="false">
	<cfargument name="parameterize" type="any" required="false">
	<cfargument name="returnAs" type="string" required="false">
	<cfargument name="callbacks" type="boolean" required="false" default="true">
	<cfargument name="includeSoftDeletes" type="boolean" required="false" default="false">
	<cfscript>
		var loc = {};
		$args(name="findByKey", args=arguments);
		arguments.include = $listClean(arguments.include);
		if (Len(arguments.key))

<cfscript>
	/*
	*  PUBLIC MODEL CLASS METHODS
	*/
	
	public any function findAll(
		string where="",
		string order,
		string group,
		string select="",
		boolean distinct="false",
		string include="",
		numeric maxRows="-1",
		numeric page="0",
		numeric perPage,
		numeric count="0",
		string handle="query",
		any cache="",
		boolean reload,
		any parameterize,
		string returnAs,
		boolean returnIncluded,
		boolean callbacks="true",
		boolean includeSoftDeletes="false",
		numeric $limit="0",
		numeric $offset="0"
	) { 
		$args(name="findAll", args=arguments);
		arguments.include = $listClean(arguments.include);
		arguments.where = $cleanInList(arguments.where);
