diff --git a/lib/navigationlib.php b/lib/navigationlib.php
index 9691409..2712dc7 100644
--- a/lib/navigationlib.php
+++ b/lib/navigationlib.php
@@ -1456,10 +1456,15 @@ class global_navigation extends navigation_node {
                             $this->add_category($subcategory, $this->addedcategories[$subcategory->parent]);
                             // Remove the category from the categories array.
                             unset($categories[$catid]);
+                        } else if ($subcategory->parent == '0') { 
+                            // The parent is the root category
+                            $this->add_category($subcategory, $this->rootnodes['courses']);
+                            // Remove the category from the categories array.                        	
+                            unset($categories[$catid]);
                         } else {
                             // We should never ever arrive here - if we have then there is a bigger
                             // problem at hand.
-                            throw coding_exception('Category path order is incorrect and/or there are missing categories');
+                            throw new coding_exception('Category path order is incorrect and/or there are missing categories');
                         }
                     }
                 }
