diff --git a/sites/all/modules/contrib/trace/trace.defines.inc b/sites/all/modules/contrib/trace/trace.defines.inc
new file mode 100644
index 0000000..91ba846
--- /dev/null
+++ b/sites/all/modules/contrib/trace/trace.defines.inc
@@ -0,0 +1,34 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ *
+ * define() statements for the trace module (used from multiple locations)
+ */
+
+define('TRACE_PATH',       dirname(__FILE__));
+define('TRACE_FORMAT',     "#%s %s [%s]");
+define('TRACE_ENABLED',    variable_get('trace_enabled', FALSE));
+define('TRACE_FILTER',     variable_get('trace_filter', 0));
+define('TRACE_PAGES',      variable_get('trace_pages', "admin*\nfavicon.ico\n"));
+define('TRACE_OUTPUT',     variable_get('trace_output', 'file'));
+define('TRACE_FILE',       variable_get('trace_file', file_directory_path() . '/trace.log'));
+define('TRACE_ERRORS',     count(array_filter(variable_get('trace_errors', array()))) > 0);
+define('TRACE_WATCHDOG',   count(array_filter(variable_get('trace_watchdog', array()))) > 0);
+define('TRACE_QUERIES',    count(array_filter(variable_get('trace_queries', array()))) > 0);
+define('TRACE_HOOKS',      count(array_filter(variable_get('trace_hooks', array()))) > 0);
+define('TRACE_REQUEST',    variable_get('trace_request', TRUE));
+define('TRACE_DEBUG',      variable_get('trace_debug', FALSE));
+define('TRACE_STACKTRACE', variable_get('trace_stacktrace', FALSE));
+define('TRACE_MAX_STRING', (integer)variable_get('trace_max_string', 100));
+define('TRACE_ERRORLINE',  variable_get('trace_errorline', FALSE));
+
+define('TRACE_ACTIVE',     TRACE_ENABLED && trace_path_enabled($_GET['q']));
+
+if (TRACE_ACTIVE) {
+  define('TRACE_TIME',     trace_time(FALSE));
+  define('TRACE_ID',       substr(uniqid(''), 5));
+  _trace_ob_start();
+}
+
diff --git a/sites/all/modules/contrib/trace/trace.module b/sites/all/modules/contrib/trace/trace.module
index 0987dfa..2ac9e96 100644
--- a/sites/all/modules/contrib/trace/trace.module
+++ b/sites/all/modules/contrib/trace/trace.module
@@ -14,30 +14,8 @@
  */
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
-define('TRACE_PATH',       dirname(__FILE__));
-define('TRACE_FORMAT',     "#%s %s [%s]");
-define('TRACE_ENABLED',    variable_get('trace_enabled', FALSE));
-define('TRACE_FILTER',     variable_get('trace_filter', 0));
-define('TRACE_PAGES',      variable_get('trace_pages', "admin*\nfavicon.ico\n"));
-define('TRACE_OUTPUT',     variable_get('trace_output', 'file'));
-define('TRACE_FILE',       variable_get('trace_file', file_directory_path() . '/trace.log'));
-define('TRACE_ERRORS',     count(array_filter(variable_get('trace_errors', array()))) > 0);
-define('TRACE_WATCHDOG',   count(array_filter(variable_get('trace_watchdog', array()))) > 0);
-define('TRACE_QUERIES',    count(array_filter(variable_get('trace_queries', array()))) > 0);
-define('TRACE_HOOKS',      count(array_filter(variable_get('trace_hooks', array()))) > 0);
-define('TRACE_REQUEST',    variable_get('trace_request', TRUE));
-define('TRACE_DEBUG',      variable_get('trace_debug', FALSE));
-define('TRACE_STACKTRACE', variable_get('trace_stacktrace', FALSE));
-define('TRACE_MAX_STRING', (integer)variable_get('trace_max_string', 100));
-define('TRACE_ERRORLINE',  variable_get('trace_errorline', FALSE));
-
-define('TRACE_ACTIVE',     TRACE_ENABLED && trace_path_enabled($_GET['q']));
-
-if (TRACE_ACTIVE) {
-  define('TRACE_TIME',     trace_time(FALSE));
-  define('TRACE_ID',       substr(uniqid(''), 5));
-  _trace_ob_start();
-}
+// these are in a separate file so that they can be included again (see trace_trace())
+require_once(dirname(__FILE__) .'/trace.defines.inc');
 
 //////////////////////////////////////////////////////////////////////////////
 
@@ -105,7 +83,7 @@ function trace_boot() {
       if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         trace('debug', '$_GET = '   . trace_format_php($_GET));
       }
-      else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+      elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
         trace('debug', '$_POST = '  . trace_format_php($_POST));
         trace('debug', '$_FILES = ' . trace_format_php($_FILES));
       }
@@ -178,7 +156,7 @@ function _trace_ob_start() {
   }
 
   if (TRACE_REQUEST) {
-    $msg = array($timestamp, $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $_SERVER['SERVER_PROTOCOL']);
+    $msg = array($timestamp, $_SERVER['REQUEST_METHOD'], request_uri(), $_SERVER['SERVER_PROTOCOL']);
     trace('request', implode(' ', $msg), 0);
   }
 
@@ -228,6 +206,10 @@ function trace_admin_log() {
  * Implements hook_trace().
  */
 function trace_trace($type, $msg, $time = NULL) {
+  // these are included here again to allow for event that this function is
+  // called before drupal is fully bootstrapped
+  require_once(dirname(__FILE__) .'/trace.defines.inc');
+
   if (TRACE_OUTPUT) {
     // Delegate to the actual selected output driver:
     $driver = 'trace_' . TRACE_OUTPUT . '_trace';
@@ -515,7 +497,7 @@ function trace_format_php($value, $depth = 0) {
       if ($depth > 1) {
         $array = array('...');
       }
-      else if (array_keys($value) === range(0, sizeof($value) - 1)) {
+      elseif (array_keys($value) === range(0, sizeof($value) - 1)) {
         $array = array_map('trace_format_php', array_values($value));
       }
       else {
