 		// since we don't return any records for calculation methods we want to skip the callbacks
 		arguments.callbacks = false;
 
-		loc.rv = findAll(argumentCollection=arguments);
+		local.rv = findAll(argumentCollection=arguments);
 		if (!StructKeyExists(arguments, "group"))
 		{
 			// when not grouping by something we just return the value itself
-			loc.rv = loc.rv[loc.alias];
-			if (!Len(loc.rv) && Len(arguments.ifNull))
-			{
-				loc.rv = arguments.ifNull;
-			}
-		}
-	</cfscript>
-	<cfreturn loc.rv>
-</cffunction>+			local.rv = local.rv[local.alias];
+			if (!Len(local.rv) && Len(arguments.ifNull))
+			{
+				local.rv = arguments.ifNull;
+			}
+		}
+		return local.rv;
+	} 
+</cfscript>
<!--- PUBLIC MODEL CLASS METHODS --->

<cffunction name="average" returntype="any" access="public" output="false">
	<cfargument name="property" type="string" required="true">
	<cfargument name="where" type="string" required="false" default="">
	<cfargument name="include" type="string" required="false" default="">
	<cfargument name="distinct" type="boolean" required="false">
	<cfargument name="parameterize" type="any" required="false">
	<cfargument name="ifNull" type="any" required="false">
	<cfargument name="includeSoftDeletes" type="boolean" required="false" default="false">
	<cfargument name="group" type="string" required="false">
	<cfscript>
		var loc = {};
		$args(name="average", args=arguments);
		arguments.type = "AVG";
		if (StructKeyExists(arguments, "group"))
		{
			loc.rv = $calculate(argumentCollection=arguments);
		}
		else
		{
			if (ListFindNoCase("cf_sql_integer,cf_sql_bigint,cf_sql_smallint,cf_sql_tinyint", variables.wheels.class.properties[arguments.property].type))
			{
				// this is an integer column so we get all the values from the database and do the calculation in ColdFusion since we can't run a query to get the average value without type casting it
				loc.values = findAll(select=arguments.property, where=arguments.where, include=arguments.include, parameterize=arguments.parameterize, includeSoftDeletes=arguments.includeSoftDeletes);
				loc.values = ListToArray(Evaluate("ValueList(loc.values.#arguments.property#)"));
				loc.rv = arguments.ifNull;
				if (!ArrayIsEmpty(loc.values))
				{
					if (arguments.distinct)
					{
						loc.tempValues = {};
						loc.iEnd = ArrayLen(loc.values);
						for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
						{
							StructInsert(loc.tempValues, loc.values[loc.i], loc.values[loc.i], true);
						}
						loc.values = ListToArray(StructKeyList(loc.tempValues));
					}
					loc.rv = ArrayAvg(loc.values);
				}
			}
			else
			{
				// if the column's type is a float or similar we can run an AVG type query since it will always return a value of the same type as the column
				loc.rv = $calculate(argumentCollection=arguments);

				// we convert the result to a string so that it is the same as what would happen if you calculate an average in ColdFusion code (like we do for integers in this function for example)
				loc.rv = JavaCast("string", loc.rv);
			}
		}
	</cfscript>
	<cfreturn loc.rv>
</cffunction>

<cffunction name="count" returntype="any" access="public" output="false">
	<cfargument name="where" type="string" required="false" default="">
	<cfargument name="include" type="string" required="false" default="">
	<cfargument name="parameterize" type="any" required="false">
	<cfargument name="includeSoftDeletes" type="boolean" required="false" default="false">
	<cfargument name="group" type="string" required="false">
	<cfscript>
		var loc = {};
		$args(name="count", args=arguments);
		arguments.type = "COUNT";
		arguments.property = ListFirst(primaryKey());

		{
			arguments.distinct = false;
		}
		local.rv = $calculate(argumentCollection=arguments);
		if (!StructKeyExists(arguments, "group") && !IsNumeric(local.rv))
		{
			local.rv = 0;
		} 
		return local.rv;
	}

	public any function maximum(
		required string property,
		string where="",
		string include="",
		any parameterize,
		any ifNull,
		boolean includeSoftDeletes="false",
		string group
	) { 
		$args(name="maximum", args=arguments);
		arguments.type = "MAX";
		local.rv = $calculate(argumentCollection=arguments); 
		return local.rv;
	}

	public any function minimum(
		required string property,
		string where="",
		string include="",
		any parameterize,
		any ifNull,
		boolean includeSoftDeletes="false",
		string group
	) { 
		$args(name="minimum", args=arguments);
		arguments.type = "MIN";
		local.rv = $calculate(argumentCollection=arguments); 
		return local.rv;
	}

	public any function sum(
		required string property,
		string where="",
		string include="",
		boolean distinct,
		any parameterize,
		any ifNull,
		boolean includeSoftDeletes="false",
		string group
	) { 
		$args(name="sum", args=arguments);
		arguments.type = "SUM";
		local.rv = $calculate(argumentCollection=arguments); 
		return local.rv;
	}

	/*
	* PRIVATE METHODS
	*/ 
	public any function $calculate(
		required string type,
		required string property,
		required string where,
		required string include,
		required any parameterize,
		boolean distinct="false",
		any ifNull="",
		required boolean includeSoftDeletes,
		string group
	){
		// start the select string with the type (`SUM`, `COUNT` etc)
		arguments.select = "#arguments.type#(";

