diff --git a/modules/features_ui/src/Form/FeaturesExportForm.php b/modules/features_ui/src/Form/FeaturesExportForm.php
index 7305f3f..f741514 100644
--- a/modules/features_ui/src/Form/FeaturesExportForm.php
+++ b/modules/features_ui/src/Form/FeaturesExportForm.php
@@ -420,7 +420,7 @@ class FeaturesExportForm extends FormBase {
 
     $details = array(
       '#type' => 'details',
-      '#title' => array('#markup' => $package['description']),
+      '#title' => array('#markup' => Xss::filterAdmin($package['description'])),
       '#description' => array('data' => $element['details']),
     );
     $element['details'] = array(
@@ -469,20 +469,6 @@ class FeaturesExportForm extends FormBase {
       return;
     }
 
-    if (!$current_bundle->isDefault()) {
-      // Assign the selected bundle to the exports.
-      $packages = $this->featuresManager->getPackages();
-      foreach ($package_names as $index => $package_name) {
-        // Rename package to use bundle prefix.
-        $package = $packages[$package_name];
-        unset($packages[$package_name]);
-        $package['machine_name'] = $current_bundle->getFullName($package['machine_name']);
-        $package['bundle'] = $current_bundle->getMachineName();
-        $this->featuresManager->savePackage($package);
-        $package_names[$index] = $package['machine_name'];
-      }
-    }
-
     $method_id = NULL;
     $trigger = $form_state->getTriggeringElement();
     $op = $form_state->getValue('op');
diff --git a/src/FeaturesBundle.php b/src/FeaturesBundle.php
index 47095ec..1022503 100644
--- a/src/FeaturesBundle.php
+++ b/src/FeaturesBundle.php
@@ -184,7 +184,7 @@ class FeaturesBundle implements FeaturesBundleInterface {
    * {@inheritdoc}
    */
   public function getShortName($machine_name) {
-    if ($this->inBundle($machine_name)) {
+    if ($machine_name != $this->getProfileName() && $this->inBundle($machine_name)) {
       return substr($machine_name, strlen($this->getMachineName()) + 1, strlen($machine_name) - strlen($this->getMachineName()) - 1);
     }
     return $machine_name;
@@ -194,7 +194,14 @@ class FeaturesBundle implements FeaturesBundleInterface {
    * {@inheritdoc}
    */
   public function inBundle($machine_name) {
-    return (strpos($machine_name, $this->machineName . '_') === 0);
+    return ($machine_name == $this->getProfileName() || strpos($machine_name, $this->machineName . '_') === 0);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isProfilePackage($machine_name) {
+    return ($this->isProfile() && $machine_name == $this->getProfileName());
   }
 
   /**
diff --git a/src/FeaturesBundleInterface.php b/src/FeaturesBundleInterface.php
index 5844b76..de82cbd 100644
--- a/src/FeaturesBundleInterface.php
+++ b/src/FeaturesBundleInterface.php
@@ -80,7 +80,7 @@ interface FeaturesBundleInterface {
    * Determines if the $machine_name is prefixed by the bundle machine name.
    *
    * @param string $machine_name
-   *   The machine name of a bundle.
+   *   The machine name of a package.
    *
    * @return bool
    *   TRUE if the machine name is prefixed by the bundle machine name.
@@ -88,6 +88,17 @@ interface FeaturesBundleInterface {
   public function inBundle($machine_name);
 
   /**
+   * Determines if the package with $machine_name is the bundle profile.
+   *
+   * @param string $machine_name
+   *   The machine name of a package.
+   *
+   * @return bool
+   *   TRUE if the machine name is prefixed by the bundle machine name.
+   */
+  public function isProfilePackage($machine_name);
+
+  /**
    * Gets the description of a bundle.
    *
    * @return string
diff --git a/src/FeaturesGenerationMethodBase.php b/src/FeaturesGenerationMethodBase.php
index 20dd5ad..b452cb0 100644
--- a/src/FeaturesGenerationMethodBase.php
+++ b/src/FeaturesGenerationMethodBase.php
@@ -85,20 +85,17 @@ abstract class FeaturesGenerationMethodBase implements FeaturesGenerationMethodI
 
     foreach ($packages as &$package) {
       list($full_name, $path) = $this->featuresManager->getExportInfo($package, $bundle);
-      $package['directory'] = $path . '/' . $full_name;
+      $package['directory'] = $path;
+
+      // If this is the profile, its directory is already assigned.
+      if (!isset($bundle) || !$bundle->isProfilePackage($package['machine_name'])) {
+        $package['directory'] .= '/' . $full_name;
+      }
+
       $this->preparePackage($package, $existing_packages, $bundle);
     }
     // Clean up the $package pass by reference.
     unset($package);
-
-    if (isset($bundle) && $bundle->isProfile()) {
-      $profile_name = $bundle->getProfileName();
-      $profile_package = $this->featuresManager->getPackage($profile_name);
-      if (isset($profile_package)) {
-        $package['directory'] = 'profiles/' . $profile_name;
-        $this->preparePackage($profile_package, $existing_packages, $bundle);
-      }
-    }
   }
 
   /**
diff --git a/src/FeaturesGenerator.php b/src/FeaturesGenerator.php
index 4b71b27..501e0ac 100644
--- a/src/FeaturesGenerator.php
+++ b/src/FeaturesGenerator.php
@@ -126,10 +126,41 @@ class FeaturesGenerator implements FeaturesGeneratorInterface {
    * {@inheritdoc}
    */
   public function generatePackages($method_id, array $package_names = array(), FeaturesBundleInterface $bundle = NULL) {
+    $this->setPackageBundleNames($package_names, $bundle);
     return $this->generate($method_id, $package_names, $bundle);
   }
 
   /**
+   * Adds the optional bundle prefix to package machine names.
+   *
+   * @param string[] &$package_names
+   *   Array of package names, passed by reference.
+   * @param \Drupal\features\FeaturesBundleInterface $bundle
+   *   The optional bundle used for the generation.  Used to generate profiles.
+   */
+  protected function setPackageBundleNames(array &$package_names, FeaturesBundleInterface $bundle = NULL) {
+    if ($bundle && !$bundle->isDefault()) {
+      $new_package_names = [];
+      // Assign the selected bundle to the exports.
+      $packages = $this->featuresManager->getPackages();
+      foreach ($package_names as $package_name) {
+        // Rename package to use bundle prefix.
+        $package = $packages[$package_name];
+        // The install profile doesn't need renaming.
+        if ($package['type'] != 'profile') {
+          unset($packages[$package_name]);
+          $package['machine_name'] = $bundle->getFullName($package['machine_name']);
+          $package['bundle'] = $bundle->getMachineName();
+          $packages[$package['machine_name']] = $package;
+        }
+        $new_package_names[] = $package['machine_name'];
+      }
+      $this->featuresManager->setPackages($packages);
+      $package_names = $new_package_names;
+    }
+  }
+
+  /**
    * Generates a file representation of configuration packages and, optionally,
    * an install profile.
    *
diff --git a/src/FeaturesManager.php b/src/FeaturesManager.php
index a693c12..adb40e7 100644
--- a/src/FeaturesManager.php
+++ b/src/FeaturesManager.php
@@ -249,7 +249,6 @@ class FeaturesManager implements FeaturesManagerInterface {
    */
   public function savePackage(array &$package) {
     if (!empty($package['machine_name'])) {
-      $this->addPackageFiles($package);
       $this->packages[$package['machine_name']] = $package;
     }
   }
@@ -472,9 +471,9 @@ class FeaturesManager implements FeaturesManagerInterface {
   /**
    * {@inheritdoc}
    */
-  public function initPackage($machine_name, $name = NULL, $description = '') {
+  public function initPackage($machine_name, $name = NULL, $description = '', $type = 'module') {
     if (!isset($this->packages[$machine_name])) {
-      return $this->packages[$machine_name] = $this->getProject($machine_name, $name, $description);
+      return $this->packages[$machine_name] = $this->getProject($machine_name, $name, $description, $type);
     }
     return NULL;
   }
@@ -751,15 +750,12 @@ class FeaturesManager implements FeaturesManagerInterface {
     $config_collection = $this->getConfigCollection();
     // Ensure the directory reflects the current full machine name.
     $package['directory'] = $package['machine_name'];
-    // Clean out previous files.
-    unset($package['files']);
     // Only add files if there is at least one piece of configuration
     // present.
     if (!empty($package['config'])) {
       // Add .info.yml files.
-      if ($package['type'] == 'module') {
-        $this->addInfoFile($package);
-      }
+      $this->addInfoFile($package);
+
       // Add configuration files.
       foreach ($package['config'] as $name) {
         $config = $config_collection[$name];
@@ -988,17 +984,20 @@ class FeaturesManager implements FeaturesManagerInterface {
 
     $full_name = $package['machine_name'];
 
+    $path = '';
+
+    // Adjust export directory to be in profile.
     if (isset($bundle) && $bundle->isProfile()) {
-      // Adjust export directory to be in profile.
-      $path = 'profiles/' . $bundle->getProfileName() . '/modules';
-    }
-    else {
-      $path = 'modules';
+      $path .= 'profiles/' . $bundle->getProfileName();
     }
 
-    $export_settings = $this->getExportSettings();
-    if (!empty($export_settings['folder'])) {
-      $path .= '/' . $export_settings['folder'];
+    // If this is not the profile package, nest the directory.
+    if (!isset($bundle) || !$bundle->isProfilePackage($package['machine_name'])) {
+      $path .= '/modules';
+      $export_settings = $this->getExportSettings();
+      if (!empty($export_settings['folder'])) {
+        $path .= '/' . $export_settings['folder'];
+      }
     }
 
     return array($full_name, $path);
diff --git a/src/FeaturesManagerInterface.php b/src/FeaturesManagerInterface.php
index 8adcf4c..6dea260 100644
--- a/src/FeaturesManagerInterface.php
+++ b/src/FeaturesManagerInterface.php
@@ -236,11 +236,13 @@ interface FeaturesManagerInterface {
    *   Human readable name of the package.
    * @param string $description
    *   Description of the package.
+   * @param string $type
+   *   The package type: 'module' or 'profile'.
    *
    * @return array
    *   The created package array.
    */
-  public function initPackage($machine_name, $name = NULL, $description = '');
+  public function initPackage($machine_name, $name = NULL, $description = '', $type = 'module');
 
   /**
    * Initializes a configuration package using module info data.
diff --git a/src/Plugin/FeaturesAssignment/FeaturesAssignmentProfile.php b/src/Plugin/FeaturesAssignment/FeaturesAssignmentProfile.php
index 56bb789..80677a2 100644
--- a/src/Plugin/FeaturesAssignment/FeaturesAssignmentProfile.php
+++ b/src/Plugin/FeaturesAssignment/FeaturesAssignmentProfile.php
@@ -41,7 +41,7 @@ class FeaturesAssignmentProfile extends FeaturesAssignmentMethodBase {
     if ($current_bundle->isProfile() && !isset($package_directories[$profile_name])) {
       // Ensure the profile package exists.
       if (empty($profile_package)) {
-        $this->featuresManager->initPackage($profile_name);
+        $this->featuresManager->initPackage($profile_name, $current_bundle->getName(), $current_bundle->getDescription(), 'profile');
       }
       // Add configuration from the Standard profile.
       $config_collection = $this->featuresManager->getConfigCollection();
@@ -51,9 +51,19 @@ class FeaturesAssignmentProfile extends FeaturesAssignmentMethodBase {
       foreach ($item_names as $item_name) {
         // If the configuration is present on the site, assign it.
         if (isset($config_collection[$item_name])) {
-          $this->featuresManager->assignConfigPackage($profile_name, [$item_name]);
-          // Reload the profile to refresh the config array after the addition.
-          $profile_package = $this->featuresManager->getPackage($profile_name);
+          // Only assign it if it's not already assigned to a package.
+          if (empty($config_collection[$item_name]['package'])) {
+            $this->featuresManager->assignConfigPackage($profile_name, [$item_name]);
+            // Reload the profile to refresh the config array after the addition.
+            $profile_package = $this->featuresManager->getPackage($profile_name);
+          }
+          // If it's already assigned, add a dependency.
+          else {
+            $machine_name = $current_bundle->getFullName($config_collection[$item_name]['package']);
+            if (!in_array($machine_name, $config_collection[$item_name]['dependencies'])) {
+              $config_collection[$item_name]['dependencies'][] = $machine_name;
+            }
+          }
         }
         // Otherwise, copy it over from Standard.
         else {
diff --git a/src/Plugin/FeaturesGeneration/FeaturesGenerationArchive.php b/src/Plugin/FeaturesGeneration/FeaturesGenerationArchive.php
index a1d8513..73fb7e9 100644
--- a/src/Plugin/FeaturesGeneration/FeaturesGenerationArchive.php
+++ b/src/Plugin/FeaturesGeneration/FeaturesGenerationArchive.php
@@ -102,14 +102,6 @@ class FeaturesGenerationArchive extends FeaturesGenerationMethodBase {
 
     $archiver = new ArchiveTar($archive_name);
 
-    // Add the Profile.
-    if (isset($bundle) && $bundle->isProfile()) {
-      $profile_package = $this->featuresManager->getPackage($bundle->getProfileName());
-      if (!empty($profile_package)) {
-        $this->generatePackage($return, $profile_package, $archiver);
-      }
-    }
-
     // Add package files.
     foreach ($packages as $package) {
       if (count($packages) == 1) {
diff --git a/src/Plugin/FeaturesGeneration/FeaturesGenerationWrite.php b/src/Plugin/FeaturesGeneration/FeaturesGenerationWrite.php
index 4777d20..bf72fd7 100644
--- a/src/Plugin/FeaturesGeneration/FeaturesGenerationWrite.php
+++ b/src/Plugin/FeaturesGeneration/FeaturesGenerationWrite.php
@@ -70,14 +70,6 @@ class FeaturesGenerationWrite extends FeaturesGenerationMethodBase {
 
     $return = [];
 
-    // Add profile files.
-    if (isset($bundle) && $bundle->isProfile()) {
-      $profile_package = $this->featuresManager->getPackage($bundle->getProfileName());
-      if (!empty($profile_package)) {
-        $this->generatePackage($return, $profile_package);
-      }
-    }
-
     // Add package files.
     // We need to update the system.module.files state because it's cached.
     // Cannot just call system_rebuild_module_data() because $listing->scan() has
