diff --git a/facets.module b/facets.module
index ff52212..bd5f163 100644
--- a/facets.module
+++ b/facets.module
@@ -13,6 +13,7 @@ use Drupal\search_api\Query\QueryInterface;
 use Drupal\views\Entity\View;
 use Drupal\Core\Entity\EntityInterface;
 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
+use Drupal\Core\Logger\RfcLogLevel;
 
 /**
  * Implements hook_help().
@@ -82,13 +83,13 @@ function facets_entity_presave(EntityInterface $entity) {
         // Check if the current display is also a facet source plugin and that
         // is removed from the view. We use the double underscore here to make
         // sure that we use core convention of "plugin:derived_plugin".
-        $test = 'views_page:' . $entity->id() . '__' . $display['id'];
-        if (array_key_exists($test, $definitions) && !array_key_exists($k, $entity->get('display'))) {
-          $entity_id = str_replace(':', '__', $test);
+        $facets_source_plugin_id = 'views_page:' . $entity->id() . '__' . $display['id'];
+        if (array_key_exists($facets_source_plugin_id, $definitions) && !array_key_exists($k, $entity->get('display'))) {
+          $entity_id = str_replace(':', '__', $facets_source_plugin_id);
           $source_entity = FacetSource::load($entity_id);
+          $sources[] = $facets_source_plugin_id;
           if (!is_null($source_entity)) {
             $source_entity->delete();
-            $sources[] = $test;
           }
         }
       }
@@ -132,23 +133,26 @@ function facets_preprocess_block(&$variables) {
  * when a view is deleted. It also deletes facets that are created on those
  * plugins.
  */
-function facets_entity_predelete(Drupal\Core\Entity\EntityInterface $entity) {
+function facets_entity_predelete(EntityInterface $entity) {
   if ($entity instanceof View) {
     $facet_source_plugin_manager = \Drupal::getContainer()
       ->get('plugin.manager.facets.facet_source');
 
     $definitions = $facet_source_plugin_manager->getDefinitions();
+
     if (!is_array($definitions)) {
       return;
     }
+
     foreach ($definitions as $plugin_id => $definition) {
       if (strpos($plugin_id, 'views_page:' . $entity->id() . '__') !== FALSE) {
         try {
           $facetManager = \Drupal::getContainer()->get('facets.manager');
         } catch (ServiceNotFoundException $e) {
-          \Drupal::logger('facets')->log(Drupal\Core\Logger\RfcLogLevel::DEBUG, 'Facet manager not found on trying to delete a view.');
+          \Drupal::logger('facets')->log(RfcLogLevel::DEBUG, 'Facet manager not found on trying to delete a view.');
           return;
         }
+
         $facets = $facetManager->getFacetsByFacetSourceId($plugin_id);
         foreach ($facets as $facet) {
           $facet->delete();
diff --git a/src/Entity/Facet.php b/src/Entity/Facet.php
index 848713d..db3f13a 100644
--- a/src/Entity/Facet.php
+++ b/src/Entity/Facet.php
@@ -484,11 +484,14 @@ class Facet extends ConfigEntityBase implements FacetInterface {
    * {@inheritdoc}
    */
   public function getFacetSource() {
-
     if (!$this->facet_source_instance && $this->facet_source_id) {
       /* @var $facet_source_plugin_manager \Drupal\facets\FacetSource\FacetSourcePluginManager */
       $facet_source_plugin_manager = \Drupal::service('plugin.manager.facets.facet_source');
-      $this->facet_source_instance = $facet_source_plugin_manager->createInstance($this->facet_source_id, ['facet' => $this]);
+      if (!$facet_source_plugin_manager->hasDefinition($this->facet_source_id)) {
+        return;
+      }
+      $this->facet_source_instance = $facet_source_plugin_manager
+        ->createInstance($this->facet_source_id, ['facet' => $this]);
     }
 
     return $this->facet_source_instance;
@@ -540,13 +543,13 @@ class Facet extends ConfigEntityBase implements FacetInterface {
       [
         'id' => $source_id,
         'name' => $this->facet_source_id,
+        'filter_key' => 'f',
+        'url_processor' => 'query_string',
       ],
       'facets_facet_source'
     );
-    $facet_source->save();
 
-    $this->facetSourceConfig = $facet_source;
-    return $this->facetSourceConfig;
+    return $facet_source;
   }
 
   /**
diff --git a/src/FacetInterface.php b/src/FacetInterface.php
index 5e9180d..135ec41 100644
--- a/src/FacetInterface.php
+++ b/src/FacetInterface.php
@@ -228,7 +228,7 @@ interface FacetInterface extends ConfigEntityInterface {
   /**
    * Returns the plugin instance of a facet source.
    *
-   * @return \Drupal\facets\FacetSource\FacetSourcePluginInterface
+   * @return \Drupal\facets\FacetSource\FacetSourcePluginInterface|null
    *   The plugin instance for the facet source.
    */
   public function getFacetSource();
diff --git a/src/FacetManager/DefaultFacetManager.php b/src/FacetManager/DefaultFacetManager.php
index c53e541..1f52f2f 100644
--- a/src/FacetManager/DefaultFacetManager.php
+++ b/src/FacetManager/DefaultFacetManager.php
@@ -167,7 +167,9 @@ class DefaultFacetManager {
    */
   public function getFacetsByFacetSourceId($facetsource_id) {
     $facets = [];
+    debug($facetsource_id);
     foreach ($this->facets as $facet) {
+      debug($facet->getFacetSourceId());
       if ($facet->getFacetSourceId() == $facetsource_id) {
         $facets[] = $facet;
       }
@@ -268,7 +270,7 @@ class DefaultFacetManager {
       // is not available on the page. Returning an empty array here is enough
       // to halt all further processing.
       $facet_source = $facet->getFacetSource();
-      if (!$facet_source->isRenderedInCurrentRequest()) {
+      if (is_null($facet_source) || !$facet_source->isRenderedInCurrentRequest()) {
         return [];
       }
     }
diff --git a/tests/src/Unit/Plugin/processor/UrlProcessorHandlerTest.php b/tests/src/Unit/Plugin/processor/UrlProcessorHandlerTest.php
index d471c7a..b8627a6 100644
--- a/tests/src/Unit/Plugin/processor/UrlProcessorHandlerTest.php
+++ b/tests/src/Unit/Plugin/processor/UrlProcessorHandlerTest.php
@@ -106,7 +106,7 @@ class UrlProcessorHandlerTest extends UnitTestCase {
     $em = $this->getMockBuilder('\Drupal\Core\Entity\EntityTypeManagerInterface')
       ->disableOriginalConstructor()
       ->getMock();
-    $em->expects($this->exactly(2))
+    $em->expects($this->exactly(1))
       ->method('getStorage')
       ->willReturn($storage);
 
