diff --git a/template.php b/template.php
index ff557ef..9f6accf 100644
--- a/template.php
+++ b/template.php
@@ -112,8 +112,9 @@ function rootcandy_links__rc_main_navigation($variables) {
   $attributes = $variables['attributes'];
   $heading = $variables['heading'];
   $output = '';
+  $num_links = is_array($links) ? count($links) : 0;
 
-  if (count($links) > 0) {
+  if ($num_links > 0) {
     $output = '';
     // Treat the heading first if it is present to prepend it to the
     // list of links.
@@ -136,7 +137,6 @@ function rootcandy_links__rc_main_navigation($variables) {
 
     $output .= '<ul' . drupal_attributes($attributes) . '>';
 
-    $num_links = count($links);
     $i = 1;
 
     $size = theme_get_setting('rootcandy_navigation_icons_size');
