diff --git a/src/Importer.php b/src/Importer.php
index 6dc4835..58fafb0 100644
--- a/src/Importer.php
+++ b/src/Importer.php
@@ -84,6 +84,13 @@ class Importer implements ImporterInterface {
   protected $scanner;
 
   /**
+   * The file map for given module.
+   *
+   * @var array
+   */
+  protected $fileMap = [];
+
+  /**
    * Constructs the default content manager.
    *
    * @param \Symfony\Component\Serializer\Serializer $serializer
@@ -112,6 +119,120 @@ class Importer implements ImporterInterface {
   }
 
   /**
+   * Given a path to a module's content folder, build the dependency graph.
+   *
+   * @param string $folder
+   *   Path to a module's content folder.
+   */
+  protected function buildGraph($folder) {
+    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
+      $this->addEntities($folder, $entity_type_id);
+    }
+  }
+
+  /**
+   * Given a base contnt folder and entity type, add contents to the graph.
+   *
+   * @param string $folder
+   *   Path to a module's content directory.
+   * @param string $entity_type_id
+   *   Entity type id to be imported.
+   */
+  protected function addEntities($folder, $entity_type_id) {
+    $reflection = new \ReflectionClass($entity_type->getClass());
+    // We are only interested in importing content entities.
+    if ($reflection->implementsInterface(ConfigEntityInterface::class)) {
+      continue;
+    }
+    if (!file_exists($folder . '/' . $entity_type_id)) {
+      continue;
+    }
+    $files = $this->scanner()->scan($folder . '/' . $entity_type_id);
+    // Default content uses drupal.org as domain.
+    // @todo Make this use a uri like default-content:.
+    $this->linkManager->setLinkDomain(static::LINK_DOMAIN);
+    // Parse all of the files and sort them in order of dependency.
+    foreach ($files as $file) {
+      $this->addFile($file);
+    }
+  }
+
+  /**
+   * Parse and decode a default content file, and add its contents to the graph.
+   *
+   * @param stdClass $file
+   *   stdClass object with name and uri properties, as returned by
+   *   DefaultContentScanner::scan
+   */
+  protected function addFile($file) {
+    $contents = $this->parseFile($file);
+    // Decode the file contents.
+    $decoded = $this->serializer->decode($contents, 'hal_json');
+    // Get the link to this entity.
+    $item_uuid = $decoded['uuid'][0]['value'];
+
+    // Throw an exception when this UUID already exists.
+    if (isset($this->fileMap[$item_uuid])) {
+      $args = array(
+        '@uuid' => $item_uuid,
+        '@first' => $this->fileMap[$item_uuid]->uri,
+        '@second' => $file->uri,
+      );
+      // Reset link domain.
+      $this->linkManager->setLinkDomain(FALSE);
+      throw new \Exception(new FormattableMarkup('Default content with uuid @uuid exists twice: @first @second', $args));
+    }
+
+    // Store the entity type with the file.
+    $file->entity_type_id = $entity_type_id;
+    // Store the file in the file map.
+    $this->fileMap[$item_uuid] = $file;
+    // Create a vertex for the graph.
+    $vertex = $this->getVertex($item_uuid);
+    $this->graph[$vertex->id]['edges'] = [];
+    if (empty($decoded['_embedded'])) {
+      // No dependencies to resolve.
+      continue;
+    }
+    // Here we need to resolve our dependencies:
+    foreach ($decoded['_embedded'] as $embedded) {
+      foreach ($embedded as $item) {
+        $uuid = $item['uuid'][0]['value'];
+        $edge = $this->getVertex($uuid);
+        $this->graph[$vertex->id]['edges'][$edge->id] = TRUE;
+      }
+    }
+  }
+
+  /**
+   * Iterate the sorted entity dependency graph and save new content.
+   *
+   * @param array $sorted
+   *   The sorted dependency tree, as returned by ::sortTree.
+   *
+   * @return array
+   *   An array of created entities, indexed by uuid.
+   */
+  protected function doImportContent($sorted) {
+    $created = [];
+    foreach ($sorted as $link => $details) {
+      if (!empty($this->fileMap[$link])) {
+        $file = $this->fileMap[$link];
+        $entity_type_id = $file->entity_type_id;
+        $resource = $this->resourcePluginManager->getInstance(array('id' => 'entity:' . $entity_type_id));
+        $definition = $resource->getPluginDefinition();
+        $contents = $this->parseFile($file);
+        $class = $definition['serialization_class'];
+        $entity = $this->serializer->deserialize($contents, $class, 'hal_json', array('request_method' => 'POST'));
+        $entity->enforceIsNew(TRUE);
+        $entity->save();
+        $created[$entity->uuid()] = $entity;
+      }
+    }
+    return $created;
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function importContent($module) {
@@ -119,73 +240,13 @@ class Importer implements ImporterInterface {
     $folder = drupal_get_path('module', $module) . "/content";
 
     if (file_exists($folder)) {
-      $file_map = [];
-      foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
-        $reflection = new \ReflectionClass($entity_type->getClass());
-        // We are only interested in importing content entities.
-        if ($reflection->implementsInterface(ConfigEntityInterface::class)) {
-          continue;
-        }
-        if (!file_exists($folder . '/' . $entity_type_id)) {
-          continue;
-        }
-        $files = $this->scanner->scan($folder . '/' . $entity_type_id);
-        // Default content uses drupal.org as domain.
-        // @todo Make this use a uri like default-content:.
-        $this->linkManager->setLinkDomain($this->linkDomain);
-        // Parse all of the files and sort them in order of dependency.
-        foreach ($files as $file) {
-          $contents = $this->parseFile($file);
-          // Decode the file contents.
-          $decoded = $this->serializer->decode($contents, 'hal_json');
-          // Get the link to this entity.
-          $item_uuid = $decoded['uuid'][0]['value'];
-
-          // Throw an exception when this UUID already exists.
-          if (isset($file_map[$item_uuid])) {
-            // Reset link domain.
-            $this->linkManager->setLinkDomain(FALSE);
-            throw new \Exception(sprintf('Default content with uuid "%s" exists twice: "%s" "%s"', $item_uuid, $file_map[$item_uuid]->uri, $file->uri));
-          }
-
-          // Store the entity type with the file.
-          $file->entity_type_id = $entity_type_id;
-          // Store the file in the file map.
-          $file_map[$item_uuid] = $file;
-          // Create a vertex for the graph.
-          $vertex = $this->getVertex($item_uuid);
-          $this->graph[$vertex->id]['edges'] = [];
-          if (empty($decoded['_embedded'])) {
-            // No dependencies to resolve.
-            continue;
-          }
-          // Here we need to resolve our dependencies:
-          foreach ($decoded['_embedded'] as $embedded) {
-            foreach ($embedded as $item) {
-              $uuid = $item['uuid'][0]['value'];
-              $edge = $this->getVertex($uuid);
-              $this->graph[$vertex->id]['edges'][$edge->id] = TRUE;
-            }
-          }
-        }
-      }
+      $this->fileMap = [];
+      $this->buildGraph($folder);
 
       // @todo what if no dependencies?
       $sorted = $this->sortTree($this->graph);
-      foreach ($sorted as $link => $details) {
-        if (!empty($file_map[$link])) {
-          $file = $file_map[$link];
-          $entity_type_id = $file->entity_type_id;
-          $resource = $this->resourcePluginManager->createInstance('entity:' . $entity_type_id);
-          $definition = $resource->getPluginDefinition();
-          $contents = $this->parseFile($file);
-          $class = $definition['serialization_class'];
-          $entity = $this->serializer->deserialize($contents, $class, 'hal_json', ['request_method' => 'POST']);
-          $entity->enforceIsNew(TRUE);
-          $entity->save();
-          $created[$entity->uuid()] = $entity;
-        }
-      }
+      $created = $this->doImportContent($sorted);
+
       $this->eventDispatcher->dispatch(DefaultContentEvents::IMPORT, new ImportEvent($created, $module));
     }
     // Reset the tree.
