--- civicrm.config.php
+++ civicrm.config.php
@@ -63,18 +63,28 @@
         // check to see if this is under sites/all/modules/contrib
         if ( strpos( $currentDir, $contribDir ) !== false ) {
             $confdir = $currentDir . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..';
+            
+            // drupal root is back one from the $confdir
+            define('DRUPAL_ROOT', $confdir . DIRECTORY_SEPARATOR . '..');
+            require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
+            
         // check to see if this is under sites/all/modules
         } else if ( strpos( $currentDir, $moduleDir ) !== false ) {
             $confdir = $currentDir . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..';
+            
+            // drupal root is back one from the $confdir
+            define('DRUPAL_ROOT', $confdir . DIRECTORY_SEPARATOR . '..');
+            require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
+            
         // check to see if this is under profiles/[PROFILE]/modules    
         } else if ( strpos( $currentDir, $profileDir ) !== false ) {
-            //
+            
+            // in the profile, we need to go back to the root and then forward
+            // this is a bit more complicated
             $drupalbase = $currentDir . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'; 
             define('DRUPAL_ROOT', $drupalbase);
             require_once $drupalbase . '/includes/bootstrap.inc';
-            //print_r(conf_path());
-            
-            
+
             $confdir = $currentDir . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . conf_path(); 
             
         } else if ( strpos( $currentDir, 'plugins' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' ) !== false ) {

--- CRM/Utils/System/Drupal.php
+++ CRM/Utils/System/Drupal.php	
@@ -608,9 +608,9 @@
     }
 
     // load drupal bootstrap
-    chdir($cmsPath);
-    define('DRUPAL_ROOT', $cmsPath);
-    require_once 'includes/bootstrap.inc';
+    //chdir($cmsPath);
+    //define('DRUPAL_ROOT', $cmsPath);
+    //require_once 'includes/bootstrap.inc';
     drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
     // explicitly setting error reporting, since we cannot handle drupal related notices
@@ -785,6 +785,7 @@
     //CRM-7803 -from d7 onward.
     $config = CRM_Core_Config::singleton();
     if (function_exists('variable_get') &&
+      function_exists('module_exists') &&
       module_exists('locale') &&
       function_exists('language_negotiation_get')
     ) {
              
