diff --git a/XHProfLib/XHProfRuns.php b/XHProfLib/XHProfRuns.php
deleted file mode 100644
index b08ed77..0000000
--- a/XHProfLib/XHProfRuns.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-
-class XHProfRunsFile implements XHProfRunsInterface {
-  private $dir;
-  private $suffix;
-
-  public function __construct() {
-    $this->dir = ini_get("xhprof.output_dir") ?: sys_get_temp_dir();
-    $this->suffix = 'xhprof';
-  }
-
-  private function gen_run_id($type) {
-    return uniqid();
-  }
-
-  private function fileName($run_id, $namespace) {
-    $file = implode('.', array($run_id, $namespace, $this->suffix));
-
-    if (!empty($this->dir)) {
-      $file = $this->dir . "/" . $file;
-    }
-    return $file;
-  }
-
-  public function getRun($run_id, $namespace) {
-    $file_name = $this->fileName($run_id, $namespace);
-
-    if (!file_exists($file_name)) {
-      throw new Exception("Could not find file $file_name");
-    }
-
-    $contents = file_get_contents($file_name);
-    return unserialize($contents);
-  }
-
-  public function getRuns($namespace = NULL) {
-    xdebug_break();
-    $files = $this->scanXHProfDir($this->dir, $namespace);
-    $files = array_map(function($f) {
-        $f['date'] = strtotime($f['date']);
-        return $f;
-      }, $files);
-    return $files;
-  }
-
-  public function scanXHProfDir($dir, $namespace = NULL) {
-    if (is_dir($dir)) {
-      $runs = array();
-      foreach (glob("{$this->dir}/*.{$this->suffix}") as $file) {
-        list($run, $source) = explode('.', basename($file));
-        $runs[] = array(
-          'run_id' => $run,
-          'namespace' => $source,
-          'basename' => htmlentities(basename($file)),
-          'date' => date("Y-m-d H:i:s", filemtime($file)),
-        );
-      }
-    }
-    return array_reverse($runs);
-  }
-}
-
diff --git a/XHProfLib/XHProfRunsInterface.php b/XHProfLib/XHProfRunsInterface.php
deleted file mode 100644
index b6cda78..0000000
--- a/XHProfLib/XHProfRunsInterface.php
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
-
-interface XHProfRunsInterface {
-  public function getRuns();
-  public function getRun($run_id, $namespace);
-}
diff --git a/XHProfLib/XHProfAggregator.php b/lib/Drupal/xhprof/Aggregator.php
similarity index 96%
rename from XHProfLib/XHProfAggregator.php
rename to lib/Drupal/xhprof/Aggregator.php
index 2dae522..3c5191b 100644
--- a/XHProfLib/XHProfAggregator.php
+++ b/lib/Drupal/xhprof/Aggregator.php
@@ -1,6 +1,13 @@
 <?php
 
-class XHProfAggregator {
+/**
+ * @file
+ * Definition of Drupal\xhprof\Aggregator.
+ */
+
+namespace Drupal\xhprof;
+
+class Aggregator {
   public $runs = array();
 
   /**
diff --git a/XHProfLib/XHProfDiffParser.php b/lib/Drupal/xhprof/DiffParser.php
similarity index 79%
rename from XHProfLib/XHProfDiffParser.php
rename to lib/Drupal/xhprof/DiffParser.php
index 77af51f..87c2c31 100644
--- a/XHProfLib/XHProfDiffParser.php
+++ b/lib/Drupal/xhprof/DiffParser.php
@@ -1,6 +1,13 @@
 <?php
 
-class XHProfDiffParser {
+/**
+ * @file
+ * Definition of Drupal\xhprof\DiffParser.
+ */
+
+namespace Drupal\xhprof;
+
+class DiffParser {
   public $parser1;
   public $parser2;
   public $totals = array();
@@ -8,8 +15,8 @@ class XHProfDiffParser {
 
   public function __construct($data1, $data2) {
     $this->data = $data;
-    $this->parser1 = new XHProfParser($data1);
-    $this->parser2 = new XHProfParser($data2);
+    $this->parser1 = new Parser($data1);
+    $this->parser2 = new Parser($data2);
     $this->parser1->getTotals();
     $this->parser2->getTotals();
   }
diff --git a/XHProfLib/XHProfParser.php b/lib/Drupal/xhprof/Parser.php
similarity index 93%
rename from XHProfLib/XHProfParser.php
rename to lib/Drupal/xhprof/Parser.php
index 1efb060..39fe2b6 100644
--- a/XHProfLib/XHProfParser.php
+++ b/lib/Drupal/xhprof/Parser.php
@@ -1,6 +1,15 @@
 <?php
 
-class XHProfParser {
+/**
+ * @file
+ * Definition of Drupal\xhprof\Parser.
+ */
+
+namespace Drupal\xhprof;
+
+use SimpleXMLElement;
+
+class Parser {
   public $data = array();
   public $totals = array();
   public $symbol_totals = array();
diff --git a/XHProfRunsFile.inc b/lib/Drupal/xhprof/RunsFile.php
similarity index 96%
rename from XHProfRunsFile.inc
rename to lib/Drupal/xhprof/RunsFile.php
index 9774ed0..dcd6ff9 100644
--- a/XHProfRunsFile.inc
+++ b/lib/Drupal/xhprof/RunsFile.php
@@ -1,11 +1,18 @@
 <?php
 
 /**
+ * @file
+ * Definition of Drupal\xhprof\RunsFile.
+ */
+
+namespace Drupal\xhprof;
+
+/**
  * XHProfRuns_Default is the default implementation of the
  * iXHProfRuns interface for saving/fetching XHProf runs.
  *
  */
-class XHProfRunsFile implements XHProfRunsInterface {
+class RunsFile implements RunsInterface {
   private $dir = '';
   private $suffix = 'xhprof';
 
diff --git a/XHProfRunsInterface.inc b/lib/Drupal/xhprof/RunsInterface.php
similarity index 83%
rename from XHProfRunsInterface.inc
rename to lib/Drupal/xhprof/RunsInterface.php
index 3a9e18b..25ba7d8 100644
--- a/XHProfRunsInterface.inc
+++ b/lib/Drupal/xhprof/RunsInterface.php
@@ -1,6 +1,13 @@
 <?php
 
-interface XHProfRunsInterface {
+/**
+ * @file
+ * Definition of Drupal\xhprof\RunsInterface.
+ */
+
+namespace Drupal\xhprof;
+
+interface RunsInterface {
   /**
   * This function gets runs based on passed parameters, column data as key, value as the value. Values
   * are escaped automatically. You may also pass limit, order by, group by, or "where" to add those values,
diff --git a/modules/xhprof_mongodb/MongodbXHProfRuns.inc b/modules/xhprof_mongodb/lib/Drupal/xhprof_mongodb/MongodbRun.php
similarity index 94%
rename from modules/xhprof_mongodb/MongodbXHProfRuns.inc
rename to modules/xhprof_mongodb/lib/Drupal/xhprof_mongodb/MongodbRun.php
index 05e20fe..e02e5bb 100644
--- a/modules/xhprof_mongodb/MongodbXHProfRuns.inc
+++ b/modules/xhprof_mongodb/lib/Drupal/xhprof_mongodb/MongodbRun.php
@@ -1,6 +1,15 @@
 <?php
 
-class MongodbXHProfRuns implements XHProfRunsInterface {
+/**
+ * @file
+ * Definition of Drupal\xhprof_mongodb;
+ */
+
+namespace Drupal\xhprof_mongodb;
+
+use Drupal\xhprof\RunsInterface;
+
+class MongodbRun implements RunsInterface {
 
   private $dir = '';
 
diff --git a/modules/xhprof_mongodb/xhprof_mongodb.info b/modules/xhprof_mongodb/xhprof_mongodb.info
index df44b01..41deec3 100644
--- a/modules/xhprof_mongodb/xhprof_mongodb.info
+++ b/modules/xhprof_mongodb/xhprof_mongodb.info
@@ -5,5 +5,3 @@ package = Development
 ;dependencies[] = devel
 dependencies[] = mongodb
 core = 7.x
-
-files[] = MongodbXHProfRuns.inc
diff --git a/modules/xhprof_mongodb/xhprof_mongodb.module b/modules/xhprof_mongodb/xhprof_mongodb.module
index 27e6ef2..02edccb 100644
--- a/modules/xhprof_mongodb/xhprof_mongodb.module
+++ b/modules/xhprof_mongodb/xhprof_mongodb.module
@@ -4,5 +4,5 @@
  * Implementation of hook_xhprof_classes_alter().
  */
 function xhprof_mongodb_xhprof_classes_alter(&$classes) {
-  $classes[] = 'MongodbXHProfRuns';
+  $classes[] = 'Drupal\xhprof_mongodb\MongodbRun';
 }
diff --git a/xhprof.admin.inc b/xhprof.admin.inc
index a556954..bc3a09d 100755
--- a/xhprof.admin.inc
+++ b/xhprof.admin.inc
@@ -27,7 +27,7 @@ function xhprof_admin_settings() {
   $form['xhprof_default_class'] = array(
     '#type' => 'radios',
     '#title' => t('XHProf storage'),
-    '#default_value' => variable_get('xhprof_default_class', 'XHProfRunsFile'),
+    '#default_value' => variable_get('xhprof_default_class', 'Drupal\xhprof\RunsFile'),
     '#options' => $options,
     '#description' => t('Choose an XHProf runs class.'),
   );
diff --git a/xhprof.info b/xhprof.info
index dc6e5f3..94387a3 100644
--- a/xhprof.info
+++ b/xhprof.info
@@ -2,6 +2,3 @@ name = xhprof
 description = XHProf integration.
 package = Development
 core = 8.x
-
-files[] = XHProfRunsInterface.inc
-files[] = XHProfRunsFile.inc
diff --git a/xhprof.install b/xhprof.install
new file mode 100644
index 0000000..08bed2d
--- /dev/null
+++ b/xhprof.install
@@ -0,0 +1,16 @@
+<?php
+
+/**
+ * Update the default XHProf class definition.
+ */
+function xhprof_update_8000() {
+  $class = variable_get('xhprof_default_class');
+  switch ($class) {
+    case 'XHProfRunsFile':
+      variable_set('xhprof_default_class', 'Drupal\xhprof\RunsFile');
+      break;
+    case 'MongodbXHProfRuns':
+      variable_set('xhprof_default_class', 'Drupal\xhprof_mongodb\MongodbRun');
+      break;
+  }
+}
diff --git a/xhprof.module b/xhprof.module
index cf5cd49..eaf0bd6 100644
--- a/xhprof.module
+++ b/xhprof.module
@@ -157,7 +157,7 @@ function xhprof_shutdown_real() {
 function xhprof_shutdown_xhprof() {
   $namespace = variable_get('site_name', '');  // namespace for your application
   $xhprof_data = xhprof_disable();
-  $class = variable_get('xhprof_default_class', 'XHProfRunsFile');
+  $class = variable_get('xhprof_default_class', 'Drupal\xhprof\RunsFile');
   $xhprof_runs = new $class();
   return $xhprof_runs->save_run($xhprof_data, $namespace);
 }
@@ -176,8 +176,6 @@ function xhprof_include() {
   if (!$included) {
     module_load_include('inc', 'xhprof');
     module_invoke_all('xhprof_load_classes');
-    module_load_include('inc', 'xhprof', 'XHProfRunsInterface');
-    module_load_include('inc', 'xhprof', 'XHProfRunsFile');
     $included = TRUE;
   }
 }
@@ -185,7 +183,7 @@ function xhprof_include() {
 function _xhprof_get_object() {
   static $xhprof_object = NULL;
   if (empty($xhprof_object)) {
-    $class = variable_get('xhprof_default_class', 'XHProfRunsFile');
+    $class = variable_get('xhprof_default_class', 'Drupal\xhprof\RunsFile');
     if (class_exists($class)) {
       $xhprof_object = new $class();
     }
@@ -198,7 +196,7 @@ function _xhprof_get_object() {
 
 function xhprof_get_classes() {
   xhprof_include();
-  $classes = array('XHProfRunsFile');
+  $classes = array('Drupal\xhprof\RunsFile');
   drupal_alter('xhprof_classes', $classes);
   return $classes;
 }
@@ -210,7 +208,7 @@ function xhprof_run_list() {
   $element = 0;
   $limit = 50;
 
-  $class = variable_get('xhprof_default_class', 'XHProfRunsFile');
+  $class = variable_get('xhprof_default_class', 'Drupal\xhprof\RunsFile');
   $xhprof_runs_impl = new $class();
   $pager_page_array = array($page);
   $pager_total_items[$element] = $xhprof_runs_impl->getCount();
@@ -299,7 +297,7 @@ function xhprof_display_run($run_ids, $symbol = NULL) {
   // future.
   extract($url_params);
 
-  $class = variable_get('xhprof_default_class', 'XHProfRunsFile');
+  $class = variable_get('xhprof_default_class', 'Drupal\xhprof\RunsFile');
   $xhprof_runs_impl = new $class();
   $output = '';
   if (isset($run_id)) {
