diff --git a/gmap.info b/gmap.info
index fa7c058..f361df7 100644
--- a/gmap.info
+++ b/gmap.info
@@ -1,11 +1,10 @@
 name = GMap
-description = Filter to allow insertion of a google map into a node
+description = Views plugins to show Google Maps from entities.
 core = 7.x
 package = Location
 configure = admin/config/services/gmap
-files[] = gmap.module
+
 files[] = gmap.views.inc
-files[] = gmap-view-gmap.tpl.php
 files[] = gmap_plugin_style_gmap.inc
 files[] = gmap_plugin_style_gmapextended.inc
 files[] = tests/gmap.test
diff --git a/gmap.module b/gmap.module
index f5050c7..739fadb 100755
--- a/gmap.module
+++ b/gmap.module
@@ -110,6 +110,8 @@ function gmap_gmap($op, &$map) {
         ),
       );
     case 'pre_theme_map':
+// The following options js-files are already attached in _gmap_pre_render_map().
+/*
       $path = drupal_get_path('module', 'gmap') . '/js/';
       // Activate markers if needed.
       if ((isset($map['behavior']['dynmarkers']) && $map['behavior']['dynmarkers']) || !empty($map['markers'])) {
@@ -129,7 +131,10 @@ function gmap_gmap($op, &$map) {
         }
 
       }
+ */
 
+// The following required js-files are already attached in  _gmap_pre_render_map() / _gmap_base_js(). 
+/*
       // add required base js
       drupal_add_js($path . 'gmap.js');
       drupal_add_js($path . 'icon.js');
@@ -138,8 +143,10 @@ function gmap_gmap($op, &$map) {
       drupal_add_js($GLOBALS['base_url'] .'/'. variable_get('file_public_path', conf_path() . '/files') . '/js/gmap_markers.js');
       drupal_add_js($path . 'gmap_marker.js');
       drupal_add_js($path . 'poly.js');
+ */
 
-
+// The following optional js-files are already attached in _gmap_pre_render_map().
+/*
       //$path = drupal_get_path('module', 'gmap') . '/js';
       if (isset($map['behavior']['locpick']) && $map['behavior']['locpick']) {
         drupal_add_js($path . 'locpick.js');
@@ -154,6 +161,7 @@ function gmap_gmap($op, &$map) {
       if (isset($map['feed']) && is_array($map['feed'])) {
         drupal_add_js(path . 'markerloader_georss.js');
       }
+ */
       break;
     case 'macro_multiple':
       return array('points', 'markers', 'feed', 'circle', 'rpolygon', 'polygon', 'line', 'style');
@@ -273,7 +281,9 @@ function gmap_gmap($op, &$map) {
 }
 
 /**
- * Get the basic js files needed for a GMap.
+ * Adds the basic js files needed for a GMap.
+ * Is called by in hook_element_info().
+ * To add js-files for a specific Views display, please use _gmap_pre_render_map().
  */
 function _gmap_base_js() {
   $ret = array();
@@ -281,7 +291,13 @@ function _gmap_base_js() {
 
   $ret[$path . '/js/gmap.js'] = array('weight' => 1);
   $ret[$path . '/js/icon.js'] = array('weight' => 2);
+  $ret[$path . '/js/marker.js'] = array('weight' => 2);
+  $ret[$path . '/js/highlight.js'] = array('weight' => 2);
+  $ret[$path . '/js/poly.js'] = array('weight' => 3);
+  $ret[$path . '/js/gmap_views_ajax.js'] = array('weight' => 3);
 
+// This function defines the general/global element.
+// The following, optional, js-files are moved to _gmap_pre_render_map(), since that is called by each instance.
   /*
     $mms = variable_get('gmap_markermanager', array());
     if (empty($mms[$mm])) {
@@ -301,9 +317,10 @@ function _gmap_base_js() {
     }
   */
 
-  $ret[$path . '/js/marker.js'] = array('weight' => 2);
-  $ret[$path . '/js/highlight.js'] = array('weight' => 2);
+//  $ret[$path . '/js/marker.js'] = array('weight' => 2);
+//  $ret[$path . '/js/highlight.js'] = array('weight' => 2);
 
+/*
   // Add the markermanager.
   // @@@TODO Need to allow multiple inclusion and have marker manager set at the map level.
   $mm = variable_get('gmap_mm_type', 'gmap');
@@ -312,11 +329,12 @@ function _gmap_base_js() {
     $ret[$path . '/thirdparty/' . $mms[$mm]['filename']] = array('weight' => 3);
   }
   $ret[$path . '/js/' . $mm . '_marker.js'] = array('weight' => 4);
+*/
   /*
     drupal_add_js(array('gmap_markermanager' => $mms[$mm]), 'setting');
   */
 
-  $ret[$path . '/js/poly.js'] = array('weight' => 3);
+//  $ret[$path . '/js/poly.js'] = array('weight' => 3);
 
   global $language;
   $file = 'api/js';
@@ -330,7 +348,9 @@ function _gmap_base_js() {
   }
   if ($query['language'] == 'zh-hans') {
     $query['language'] = 'zh-CN';
-    $ret[url(gmap_views_protocol() . '://ditu.google.cn/maps/' . $file, array('query' => $query))] = array(
+    // There is no https:// version of this domain, so this can be hard coded.
+//    $ret[url(gmap_views_protocol() . '://ditu.google.cn/maps/' . $file, array('query' => $query))] = array(
+    $ret[url('http' . '://ditu.google.cn/maps/' . $file, array('query' => $query))] = array(
       'type' => 'external',
       'weight' => 2,
     );
@@ -349,7 +369,8 @@ function _gmap_base_js() {
     );
   }
 
-  $ret[$GLOBALS['base_url'] .'/'. variable_get('file_public_path', conf_path() . '/files') . '/js/gmap_markers.js'] = array(
+  $ret['/' . variable_get('file_public_path', conf_path() . '/files') . '/js/gmap_markers.js'] = array(
+//  $ret[$GLOBALS['base_url'] . '/' . variable_get('file_public_path', conf_path() . '/files') . '/js/gmap_markers.js'] = array(
     'type' => 'external',
     'weight' => 2,
   );
@@ -362,11 +383,15 @@ function _gmap_base_js() {
  * If you are going to include a custom JS file that extends GMap, you probabaly
  * want to call this first to ensure that the core js files have been added.
  */
-function _gmap_doheader() {
-  static $gmap_initialized = FALSE;
-  if ($gmap_initialized) {
-    return;
-  }
+// This function is removed. All js-files are already attached in _pre_render() or _gmap_base_js().
+//function _gmap_doheader() {
+//  static $gmap_initialized = FALSE;
+//  if ($gmap_initialized) {
+//    return;
+//  }
+//  $gmap_initialized = TRUE;
+//
+/*
   $gmap_path = drupal_get_path('module', 'gmap');
   $mm = variable_get('gmap_mm_type', 'gmap');
   $mms = variable_get('gmap_markermanager', array());
@@ -385,33 +410,35 @@ function _gmap_doheader() {
   if (isset($mms[$mm]['filename'])) {
 //    drupal_add_js($gmap_path . '/thirdparty/' . $mms[$mm]['filename']);
   }
-//  drupal_add_js($gmap_path . '/js/marker.js');
-//  drupal_add_js($gmap_path . '/js/highlight.js');
 //  drupal_add_js($gmap_path . '/js/' . $mm . '_marker.js');
   drupal_add_js(array('gmap_markermanager' => $mms[$mm]), 'setting');
+ */
 // @@@
-  drupal_add_js($gmap_path . '/js/poly.js');
+//  drupal_add_js($gmap_path . '/js/marker.js');
+//  drupal_add_js($gmap_path . '/js/highlight.js');
+//  drupal_add_js($gmap_path . '/js/poly.js');
+
+//  global $language;
+//  $file = 'api/js';
+//  $query = array(
+//    'v' => variable_get('gmap_api_version', GMAP_API_VERSION),
+//    'language' => $language->language,
+//    'sensor' => 'false',
+//  );
+//  if ($query['language'] == 'zh-hans') {
+//    $query['language'] = 'zh-CN';
+//    drupal_add_js(url('http://ditu.google.cn/maps/' . $file, array('query' => $query)));
+//  }
+//  elseif ($query['language'] == 'zh-hant') {
+//    $query['language'] = 'zh-TW';
+//    drupal_add_js(url('http://maps.google.com/maps/' . $file, array('query' => $query)));
+//  }
+//  else {
+//    drupal_add_js(url('http://maps.google.com/maps/' . $file, array('query' => $query)));
+//  }
+
+//}
 
-  global $language;
-  $file = 'api/js';
-  $query = array(
-    'v' => variable_get('gmap_api_version', GMAP_API_VERSION),
-    'language' => $language->language,
-    'sensor' => 'false',
-  );
-  if ($query['language'] == 'zh-hans') {
-    $query['language'] = 'zh-CN';
-    drupal_add_js(url('http://ditu.google.cn/maps/' . $file, array('query' => $query)));
-  }
-  elseif ($query['language'] == 'zh-hant') {
-    $query['language'] = 'zh-TW';
-    drupal_add_js(url('http://maps.google.com/maps/' . $file, array('query' => $query)));
-  }
-  else {
-    drupal_add_js(url('http://maps.google.com/maps/' . $file, array('query' => $query)));
-  }
-  $gmap_initialized = TRUE;
-}
 
 /**
  * Convert a macro string into a GMap array.
@@ -735,26 +762,48 @@ function gmap_element_info() {
  * Pre render function to make sure all required JS is available.
  */
 function _gmap_pre_render_map($element) {
-  $path = drupal_get_path('module', 'gmap') . '/js';
+  $path = drupal_get_path('module', 'gmap');
   if (!isset($element['#gmap_settings'])) {
     $element['#gmap_settings'] = $element['#settings'];
   }
   $map = $element['#gmap_settings'];
   if (isset($map['behavior']['locpick']) && $map['behavior']['locpick']) {
-    $element['#attached']['js']["$path/locpick.js"] = array('weight' => 2);
+    $element['#attached']['js']["$path/js/locpick.js"] = array('weight' => 2);
   }
-
   if (!empty($map['markers']) || !empty($map['lines'])) {
-    $element['#attached']['js']["$path/markerloader_static.js"] = array('weight' => 5);
+    $element['#attached']['js']["$path/js/markerloader_static.js"] = array('weight' => 5);
   }
   if (!empty($map['shapes'])) {
-    $element['#attached']['js']["$path/shapeloader_static.js"] = array('weight' => 5);
-    $element['#attached']['js']["$path/gmap_shapes.js"] = array('weight' => 5);
+    $element['#attached']['js']["$path/js/shapeloader_static.js"] = array('weight' => 5);
+    $element['#attached']['js']["$path/js/gmap_shapes.js"] = array('weight' => 5);
   }
   if (isset($map['feed']) && is_array($map['feed'])) {
-    $element['#attached']['js']["$path/markerloader_georss.js"] = array('weight' => 5);
+    $element['#attached']['js']["$path/js/markerloader_georss.js"] = array('weight' => 5);
   }
 
+  // Add the markermanager.
+  if ((isset($map['behavior']['dynmarkers']) && $map['behavior']['dynmarkers']) || !empty($map['markers'])) {
+    static $header_set = FALSE;
+    if (!$header_set) {
+      $header_set = TRUE;
+      if (!variable_get('gmap_marker_file', FALSE)) {
+        gmap_regenerate_markers();
+      }
+    }
+  }
+  $mm = variable_get('gmap_mm_type', 'gmap');
+  $mms = variable_get('gmap_markermanager', array());
+  // If you really really want to override the marker manager, implement
+  // this, take $mm by ref, and have fun. --Bdragon
+  if (function_exists('_gmap_markermanager_override')) {
+    _gmap_markermanager_override($mm);
+  }
+
+  if (isset($mms[$mm]['filename'])) {
+    $element['#attached']['js'][$path . '/thirdparty/js/' . $mms[$mm]['filename']] = array('weight' => 3);
+  }
+  $element['#attached']['js'][$path . '/js/' . $mm . '_marker.js'] = array('weight' => 5);
+
   return $element;
 }
 
@@ -1006,8 +1055,6 @@ function theme_gmap($variables) {
   // Track the mapids we've used already.
   static $mapids = array();
 
-  _gmap_doheader();
-
   $mapid = FALSE;
   if (isset($element['#map']) && $element['#map']) {
     // The default mapid is #map.
@@ -1414,6 +1461,8 @@ function gmap_views_plugins() {
 /**
  * Implementation of hook_views_pre_render().
  */
+// This function is removed, and the js is added in _gmap_base_js
+/*
 function gmap_views_pre_render(&$view) {
   static $gmap_processed;
   // Add js only for gmap style views with ajax and not already processed.
@@ -1427,6 +1476,7 @@ function gmap_views_pre_render(&$view) {
   // Add js with new views callback.
   drupal_add_js(drupal_get_path('module', 'gmap') . '/js/gmap_views_ajax.js', array('group' => JS_DEFAULT));
 }
+*/
 
 /**
  * Implementation of hook_views_ajax_data_alter().
@@ -1437,7 +1487,7 @@ function gmap_views_ajax_data_alter(&$commands, $view) {
   foreach ($view->display as $display) {
     $plugin_styles[] = $display->display_options['style_plugin'];
   }
-  if (!(in_array('gmap', $plugin_styles) || in_array('gmap', $plugin_styles))) {
+  if (!(in_array('gmap', $plugin_styles))) {
     return;
   }
 
diff --git a/gmap_plugin_style_gmap.inc b/gmap_plugin_style_gmap.inc
index e97fdec..4e915e6 100755
--- a/gmap_plugin_style_gmap.inc
+++ b/gmap_plugin_style_gmap.inc
@@ -102,8 +102,8 @@ class gmap_plugin_style_gmap extends views_plugin_style {
       $lon_field = 'gmap_lon';
     }
     else if ($this->options['datasource'] == 'geofield') {
-      $lat_field = 'lat';
-      $lon_field = 'lon';
+      $lat_field = 'field_' . $this->options['geofield']; // "[0]['raw']['lat']";
+      $lon_field = 'field_' . $this->options['geofield']; // "[0]['raw']['lon']";
     }
     // Determine fieldname for latitude and longitude fields.
     else if ($this->options['datasource'] == 'fields') {
@@ -179,15 +179,11 @@ class gmap_plugin_style_gmap extends views_plugin_style {
           $lat = (float)$row->{$lat_field};
           $lon = (float)$row->{$lon_field};
         }
-        else if ($this->options['datasource'] == 'geofield') {
-          $geofield_name = 'field_' . $this->options['geofield'];
-          $geofield = isset($row->{$geofield_name}[0]['raw']) ? $row->{$geofield_name}[0]['raw'] : NULL;
-          if ($geofield) {
-            $lat = (float)$geofield[$lat_field];
-            $lon = (float)$geofield[$lon_field];
-          }
+        elseif ($this->options['datasource'] == 'geofield') {
+          $lat = isset($row->{$lat_field}['0']['raw']['lat']) ? (float) $row->{$lat_field}['0']['raw']['lat'] : NULL;
+          $lon = isset($row->{$lon_field}['0']['raw']['lon']) ? (float) $row->{$lon_field}['0']['raw']['lon'] : NULL;
         }
-        else if ($this->options['datasource'] == 'fields') {
+        elseif ($this->options['datasource'] == 'fields') {
           $custom_field_latname = 'field_' . $lat_field;
           $custom_field_lonname = 'field_' . $lon_field;
           $custom_field_lat = isset($row->{$custom_field_latname}[0]['raw']) ? $row->{$custom_field_latname}[0]['raw'] : NULL;
