diff --git a/dart.admin.inc b/dart.admin.inc
index 8ddac36..117da88 100644
--- a/dart.admin.inc
+++ b/dart.admin.inc
@@ -63,6 +63,12 @@ function dart_admin_settings() {
     '#description' => t('The value to use when no "zone" is specified on a given page.'),
     '#maxlength' => 32,
   );
+  $form['settings']['tag_settings']['dart_load_last'] = array(
+    '#type'           => 'checkbox',
+    '#title'          => t('Load ads last'),
+    '#default_value'  => variable_get('dart_load_last', '0'),
+    '#description'    => t('Wait until the entire page has loaded before loading ads. This will allow your pages to load faster but may cause empty spaces to appear on your pages before the ads load. <strong>You must use this option if you are loading ad tags asyncronously.</strong>'),
+  );
 
   // Global display options.
   $form['settings']['display_options'] = array(
@@ -244,7 +250,7 @@ function theme_dart_global_defaults_form($variables) {
     '!site' => drupal_render($form[$fields['site']]),
     '!zone' => drupal_render($form[$fields['zone']]),
   );
-  
+
   $form[$element_name] = array(
     '#prefix' => '<div class="form-item"><label>' . ucwords($mode) . ' prefix . site / zone</label>',
     '#markup' => '<div class="container-inline">' . t('!prefix . !site / !zone', $replacements) . '</div>',
diff --git a/dart.js b/dart.js
index 79c4507..5065b9f 100644
--- a/dart.js
+++ b/dart.js
@@ -1,3 +1,4 @@
+(function($) {
 
 /**
  * Create a DART object to handle tagging functionality
@@ -12,41 +13,24 @@ Drupal.DART.settings = {
 };
 
 /**
- * If there are tags in the loadLastTags, then load them where they belong.
- */
-Drupal.behaviors.DART = function() {
-  if (typeof(Drupal.DART.settings.loadLastTags) == 'object') {
-    $('.dart-tag:visible').each( function() {
-      if(!$(this).hasClass('dart-processed')) {
-        var regex = /dart-name-(\w+)$/;
-        var result = regex.exec($(this).attr('class'));
-        var scriptTag = Drupal.DART.tag(Drupal.DART.settings.loadLastTags[result[1]]);
-
-        $(this).writeCapture().append(scriptTag).addClass('dart-processed');
-      }
-    });
-  }
-}
-
-/**
  * Using document.write, add a DART tag to the page
  */
 Drupal.DART.tag = function(tag) {
   tag = typeof(tag) == 'string' ? eval('(' + tag + ')') : tag;
 
   var tagname = tag.settings.options.method == 'adj' ? 'script' : 'iframe';
-  var options = tag.settings.options.method == 'adj' ? 'type="text/javascript"' : 'frameborder="0" scrolling="no" width="' + tag.sz.split("x")[0] + '" height="' + tag.sz.split("x")[1] + '"';;
+  var options = tag.settings.options.method == 'adj' ? 'type="text/javascript"' : 'frameborder="0" scrolling="no" width="' + tag.sz.split("x")[0] + '" height="' + tag.sz.split("x")[1] + '"';
 
-  ad  = '<' + tagname + ' ' + options + ' src="';
+  ad = '<' + tagname + ' ' + options + ' src="';
   ad += dart_url + "/";
-  ad += tag.network_id != '' ? tag.network_id + "/" : "";
+  ad += tag.network_id !== '' ? tag.network_id + "/" : "";
   ad += tag.settings.options.method + "/";
   ad += tag.prefix + '.' + tag.site + "/" + tag.zone + ";";
   ad += this.keyVals(tag.key_vals);
 
   // Allow other modules to include js that can manipulate each key|val.
-  rendered_ad = ($ != undefined) ? $(document).triggerHandler('dart_tag_render', [ad]) : undefined;
-  ad = rendered_ad != undefined ? rendered_ad : ad; ad += '"></' + tagname + '>';
+  rendered_ad = ($ !== undefined) ? $(document).triggerHandler('dart_tag_render', [ad]) : undefined;
+  ad = rendered_ad !== undefined ? rendered_ad : ad; ad += '"></' + tagname + '>';
 
   if (Drupal.DART.settings.writeTags) {
     document.write(ad);
@@ -56,7 +40,7 @@ Drupal.DART.tag = function(tag) {
   // console.log(tag);
 
   return ad;
-}
+};
 
 /**
  * Format a key|val pair into a dart tag key|val pair.
@@ -66,11 +50,11 @@ Drupal.DART.keyVal = function(key, val, useEval) {
   kvp += useEval ? eval(val) : val;
   kvp += key == "ord" ? "?" : ";";
   return(kvp);
-}
+};
 
 /**
  * Loop through an object and create kay|val pairs.
- * 
+ *
  * @param vals
  *   an object in this form:
  *   {
@@ -89,4 +73,21 @@ Drupal.DART.keyVals = function(vals) {
     }
   }
   return ad;
-}
+};
+
+/**
+ * If there are tags in the loadLastTags, then load them where they belong.
+ */
+Drupal.behaviors.DART = {
+  attach: function(context) {
+    if (typeof(Drupal.DART.settings.loadLastTags) == 'object') {
+      $('.dart-tag:visible').not('.dart-processed').each(function() {
+        var regex = /dart-name-(\w+)$/;
+        var result = regex.exec($(this).attr('class'));
+        var scriptTag = Drupal.DART.tag(Drupal.DART.settings.loadLastTags[result[1]]);
+        $(this).writeCapture().append(scriptTag).addClass('dart-processed');
+      });
+    }
+  }
+};
+})(jQuery);
diff --git a/dart.module b/dart.module
index c7150d4..2f03c25 100644
--- a/dart.module
+++ b/dart.module
@@ -372,9 +372,10 @@ function dart_preprocess_page(&$variables) {
     $inline_js .= 'Drupal.DART.settings.loadLastTags = {};' . "\n";
   }
 
-  // Include the inline js & dart.js file.
-  drupal_add_js(trim($inline_js, "\n"), array('type' => 'inline', 'scope' => JS_DEFAULT));
+  // Include the inline js & dart.js file. Dart.js must be included first
+  // because the inline_js can reference variables defined in dart.js.
   drupal_add_js(drupal_get_path('module', 'dart') . '/dart.js');
+  drupal_add_js(trim($inline_js, "\n"), array('type' => 'inline', 'scope' => 'header'));
 
   // Regenerate scripts variable to incorporate newly added scripts.
   $variables['scripts'] = drupal_get_js();
@@ -415,7 +416,7 @@ function dart_test_page() {
         '#markup' => module_exists('devel') ? kpr($tag, TRUE) : '',
       ),
       '#sorted' => TRUE,
-    );    
+    );
   }
 
   return $content;
@@ -563,7 +564,7 @@ function _dart_get_page_key_vals() {
 function template_preprocess_dart_tag(&$variables) {
   $tag = $variables['tag'];
 
-  $variables['attributes_array']['class'] = 'dart-tag dart-name-' . $tag->machinename;
+  $variables['classes_array'][] = 'dart-name-' . $tag->machinename;
   $variables['json_tag'] = drupal_json_encode($tag);
   $variables['load_last']   = variable_get('dart_load_last', '0');
 
