            (ext-file (concat dir "extensions.el")))
       (progn 
         ;; packages
-        (unless (not (file-exists-p pkg-file))
+        (when (file-exists-p pkg-file)
           (load pkg-file)
           (dolist (pkg (eval (intern (format "%s-packages" (symbol-name sym)))))
             (unless (member pkg dotspacemacs-excluded-packages)
-              (puthash pkg sym spacemacs-all-packages))))
+              (contribsys//add-layer-to-hash pkg sym spacemacs-all-packages))))
         ;; extensions
-        (unless (not (file-exists-p ext-file))
+        (when (file-exists-p ext-file)
           (load ext-file)
           (dolist (pkg (eval (intern (format "%s-pre-extensions"
                                              (symbol-name sym)))))
             (unless (member pkg dotspacemacs-excluded-packages)
-              (puthash pkg sym spacemacs-all-pre-extensions)))
+              (contribsys//add-layer-to-hash
+               pkg sym spacemacs-all-pre-extensions)))
           (dolist (pkg (eval (intern (format "%s-post-extensions"
                                              (symbol-name sym)))))
             (unless (member pkg dotspacemacs-excluded-packages)
-              (puthash pkg sym spacemacs-all-post-extensions)))))))
+              (contribsys//add-layer-to-hash
+               pkg sym spacemacs-all-post-extensions)))))))
   ;; number of chuncks for the loading screen
   (let ((total (+ (ht-size spacemacs-all-packages)
                   (ht-size spacemacs-all-pre-extensions)

(defun contribsys/delete-orphan-packages ()
  "Delete all the orphan packages."
  (interactive)
  (let* ((dependencies (contribsys/get-package-dependencies))
         (implicit-packages (contribsys/get-implicit-packages))
         (orphans (contribsys/get-orphan-packages implicit-packages
                                                  dependencies))

  "Initialize all the declared packages."
  (ht-each 'contribsys/initialize-package spacemacs-all-packages))

(defun contribsys/initialize-package (pkg layers)
  "Initialize the package PKG from the configuration layers LAYERS."
  (dolist (layer layers)
    (let* ((init-func (intern (format "%s/init-%s" (symbol-name layer) pkg))))
      (spacemacs/loading-animation)
      (if (and (package-installed-p pkg) (fboundp init-func))
          (progn  (message "(Spacemacs) Initializing %s:%s..."
                           (symbol-name layer) pkg)
                  (funcall init-func))))))

(defun contribsys/initialize-extensions (ext-list)
  "Initialize all the declared extensions in EXT-LIST hash table."
  (ht-each 'contribsys/initialize-extension ext-list))

(defun contribsys/initialize-extension (ext layers)
  "Initialize the extension EXT from the configuration layer LSYM."
  (dolist (layer layers)
    (let* ((l (assq layer spacemacs-config-layers))
           (ext-dir (plist-get (cdr l) :ext-dir))
           (init-func (intern (format "%s/init-%s" (symbol-name layer) ext))))
      (add-to-list 'load-path (format "%s%s/" ext-dir ext))
      (spacemacs/loading-animation)
      (message "(Spacemacs) Initializing %s:%s..." (symbol-name layer) ext)
      (if (fboundp init-func) (funcall init-func)))))

(defun contribsys/initialized-packages-count ()
  "Return the number of initialized packages and extensions."
