 		application.$wheels.URLRewriting = "Off";
 	}
 
-	// set datasource name to same as the folder the app resides in unless the developer has set it with the global setting already
+	// Set datasource name to same as the folder the app resides in unless the developer has set it with the global setting already.
 	if (StructKeyExists(this, "dataSource")) {
 		application.$wheels.dataSourceName = this.dataSource;
 	} else {
 		application.$wheels.dataSourceName = LCase(ListLast(GetDirectoryFromPath(GetBaseTemplatePath()), Right(GetDirectoryFromPath(GetBaseTemplatePath()), 1)));
 	}
+
 	application.$wheels.dataSourceUserName = "";
 	application.$wheels.dataSourcePassword = "";
 	application.$wheels.transactionMode = "commit";
 
-	// dbmigrate
+	// Create migrations object and set default settings.
 	application.$wheels.dbmigrate = $createObjectFromRoot(path="wheels", fileName="dbmigrate", method="init");
 	application.$wheels.dbmigrateTableName = "schemainfo";
 	application.$wheels.dbmigrateWriteSQLFiles = false;

	application.$wheels.cache.query = {};
	application.$wheels.cacheLastCulledAt = Now();

	// set up paths to various folders in the framework
	application.$wheels.webPath = Replace(request.cgi.script_name, Reverse(spanExcluding(Reverse(request.cgi.script_name), "/")), "");
	application.$wheels.rootPath = "/" & ListChangeDelims(application.$wheels.webPath, "/", "/");
	application.$wheels.rootcomponentPath = ListChangeDelims(application.$wheels.webPath, ".", "/");
	application.$wheels.wheelsComponentPath = ListAppend(application.$wheels.rootcomponentPath, "wheels", ".");

	// set environment either from the url or the developer's environment.cfm file
	if (StructKeyExists(URL, "reload") && !IsBoolean(URL.reload) && Len(url.reload) && StructKeyExists(application.$wheels, "reloadPassword") && (!Len(application.$wheels.reloadPassword) || (StructKeyExists(URL, "password") && URL.password == application.$wheels.reloadPassword))) {
		application.$wheels.environment = URL.reload;
	} else {
		$include(template="config/environment.cfm");
	}

	// rewrite settings based on web server rewrite capabilites
	application.$wheels.rewriteFile = "rewrite.cfm";
	if (Right(request.cgi.script_name, 12) == "/" & application.$wheels.rewriteFile) {
		application.$wheels.URLRewriting = "On";

		}
	}

	// Reload the plugins each time we reload the application.
	$loadPlugins();

	// Allow developers to inject plugins into the application variables scope.
	if (!StructIsEmpty(application.$wheels.mixins)) {
		$include(template="wheels/plugins/standalone/injection.cfm");
	}

	// Create the mapper that will handle creating routes.
	// Needs to be before $loadRoutes and after $loadPlugins.
	application.$wheels.mapper = $createObjectFromRoot(path="wheels", fileName="Mapper", method="$init");

	// Load developer routes and adds the default CFWheels routes (unless the developer has specified not to).
	$loadRoutes();

	// Create the dispatcher that will handle all incoming requests.
	application.$wheels.dispatch = $createObjectFromRoot(path="wheels", fileName="Dispatch", method="$init");

	// Assign it all to the application scope in one atomic call.
	application.wheels = application.$wheels;
	StructDelete(application, "$wheels");

	// Run the developer's on application start code.
	$include(template="#application.wheels.eventPath#/onapplicationstart.cfm");

	// Redirect away from reloads on GET requests.
	if (application.wheels.redirectAfterReload && StructKeyExists(url, "reload") && cgi.request_method == "get") {
		if (StructKeyExists(cgi, "path_info") && Len(cgi.path_info)) {
			local.url = cgi.path_info;
		} else if (StructKeyExists(cgi, "path_info")) {
			local.url = "/";
		} else {
			local.url = cgi.script_name;
		}
		local.oldQueryString = ListToArray(cgi.query_string, "&");
		local.newQueryString = [];
		local.iEnd = ArrayLen(local.oldQueryString);
		for (local.i = 1; local.i <= local.iEnd; local.i++) {
			local.keyValue = local.oldQueryString[local.i];
			local.key = ListFirst(local.keyValue, "=");
			if (!ListFindNoCase("reload,password", local.key)) {
				ArrayAppend(local.newQueryString, local.keyValue);
			}
		}
		if (ArrayLen(local.newQueryString)) {
			local.queryString = ArrayToList(local.newQueryString, "&");
			local.url = "#local.url#?#local.queryString#";
		}
		$location(url=local.url, addToken=false);
	}
}
