diff --git a/src/Plugin/Block/PhpInsightsBlock.php b/src/Plugin/Block/PhpInsightsBlock.php
index d613068..ba953f6 100644
--- a/src/Plugin/Block/PhpInsightsBlock.php
+++ b/src/Plugin/Block/PhpInsightsBlock.php
@@ -3,11 +3,12 @@
 namespace Drupal\phpinsights\Plugin\Block;
 
 use Drupal\Core\Block\BlockBase;
-use Symfony\Component\DependencyInjection\ContainerInterface;
-use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
 use GuzzleHttp\Client;
 use GuzzleHttp\Exception\ClientException;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * @file
@@ -28,20 +29,28 @@ class PhpInsightsBlock extends BlockBase implements ContainerFactoryPluginInterf
   /**
    * The config factory.
    *
-   * @var \Drupal\Core\Config\config_factoryInterface
+   * @var \Drupal\Core\Config\ConfigFactoryInterface
    */
   protected $configFactory;
 
+  /**
+   * The backend cache.
+   *
+   * @var \Drupal\Core\Cache\CacheBackendInterface
+   */
+  protected $cacheBackend;
+
   protected $apiKey;
   protected $userID;
   protected $newTab;
 
   /**
-   * Class Constructor.
+   * {@inheritDoc}
    */
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, CacheBackendInterface $cache_backend) {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->configFactory = $config_factory;
+    $this->cacheBackend = $cache_backend;
   }
 
   /**
@@ -52,7 +61,8 @@ class PhpInsightsBlock extends BlockBase implements ContainerFactoryPluginInterf
       $configuration,
       $plugin_id,
       $plugin_definition,
-      $container->get('config.factory')
+      $container->get('config.factory'),
+      $container->get('cache.default')
     );
   }
 
@@ -108,7 +118,7 @@ class PhpInsightsBlock extends BlockBase implements ContainerFactoryPluginInterf
    */
   private function projects() {
     // Get projects from the cache.
-    $cache = \Drupal::cache();
+    $cache = $this->cacheBackend;
     $cached_data = $cache->get('phpinsights:projects');
     if ($cached_data) {
       return unserialize($cached_data->data);
@@ -138,6 +148,7 @@ class PhpInsightsBlock extends BlockBase implements ContainerFactoryPluginInterf
 
     // Loop while you get not empty JSON response.
     while ($loop_through) {
+      $projects_json = [];
       try {
         // @TODO Replace the Uri.
         $response = $client->get('http://api.behance.net/v2/users/' .
@@ -152,7 +163,7 @@ class PhpInsightsBlock extends BlockBase implements ContainerFactoryPluginInterf
       }
 
       if ($response_code == 200) {
-        if ($projects_json['projects']) {
+        if (isset($projects_json['projects']) && count($projects_json['projects']) > 0) {
           foreach ($projects_json['projects'] as $projects) {
             $all_projects[] = $projects;
           }
@@ -176,7 +187,7 @@ class PhpInsightsBlock extends BlockBase implements ContainerFactoryPluginInterf
    */
   private function tags() {
     // Get tags from the cache.
-    $cache = \Drupal::cache();
+    $cache = $this->cacheBackend;
     $cached_data = $cache->get('phpinsights:tags');
     if ($cached_data) {
       return unserialize($cached_data->data);
