diff --git a/weblinks.test b/weblinks.test
index e643de3..66f2eca 100644
--- a/weblinks.test
+++ b/weblinks.test
@@ -114,12 +114,16 @@ class WeblinksTestCase extends DrupalWebTestCase {
     $count_unpub = db_query("SELECT COUNT(nid) FROM {node} WHERE type='weblinks' AND status=0")->fetchField();
     $this->assertEqual($count_unpub, 1, t('Correct number of unpublished links in the {node} db table.'), 'Basic');
 
-    // Is the promoted link on the home page? - test page 3.
+    // Check that the url is sucessfully stored in the database
+    $check = db_query("SELECT url FROM {weblinks} WHERE nid = :nid", array(':nid' => $link1->nid))->fetchField();
+    $this->assertEqual($link1->url, $check, t('URL for link1 is successfully stored.'), 'Basic');
+
+    // Is the promoted link on the home page?
     $content = $this->drupalGet('node');
     //$this->pass(check_plain($content));
     $this->assertText($link1->title, t('Link is promoted to the home page.'), 'Basic');
 
-    // Go to the weblinks main page - test page 4.
+    // Go to the weblinks main page.
     $content = $this->drupalGet('weblinks');
     //$this->pass(check_plain($content));
     $this->assertText($link1->title, t('Node title appears on the list.'), 'Basic');
@@ -133,41 +137,71 @@ class WeblinksTestCase extends DrupalWebTestCase {
     //debug($link1_shouldbe, 'In normal mode, $link1_shouldbe');
     $this->assertRaw($link1_shouldbe, t('URL displayed in URL mode.'), 'Basic');
 
-    // Switch mode to "redirect" for 'Enable click-tracking' - test page 5.
-    variable_set('weblinks_redirect', TRUE);
+    // Check that the fieldset for vocab 0 (undefined group) exists, and has the
+    // default attributes of collapsible but not collapsed.
+    $fieldset = $this->xpath('//fieldset[@id="weblinks-fieldset-0"]');
+    $this->assertTrue(!empty($fieldset), 'Fieldset for vocabulary 0 exists.', 'Basic');
+    $fieldset_attributes = (array)$fieldset[0]->attributes();
+    $fieldset_class = $fieldset_attributes['@attributes']['class'];
+    debug($fieldset_class, '$fieldset_class');
+    $this->assertTrue(stristr($fieldset_class, 'collapsible'), 'The fieldset is collapsible.', 'Basic');
+    $this->assertFalse(stristr($fieldset_class, 'collapsed'), 'The fieldset is not collapsed.', 'Basic');
+
+    // Check that a normal user can't admin.
+    $this->drupalGet('admin/config/content/weblinks');
+    $this->assertResponse(403, t('Access is denied on the administration page.'), 'Basic');
+
+    // Prepare an admin user.
+    $admin = $this->drupalCreateUser(array('access content', 'access web links', 'administer weblinks'));
+    $this->drupalLogin($admin);
+
+    // Set the default to collapsed fieldsets and switch mode to 'redirect'
+    $settings = array(
+      'weblinks_collapsed' => '1',
+      'weblinks_redirect' => '1',
+    );
+    $this->drupalPost('admin/config/content/weblinks', $settings, t('Save configuration'));
+
     $content = $this->drupalGet('weblinks');
     $link1_shouldbe = '<a href="' . url('weblinks/goto/' . $link1->nid) . '" target="_blank" title="' . $link1->title . '">' . $link1->url . '</a>';
-    //debug($link1_shouldbe, 'In redirect mode, $link1_shouldbe');
-    //debug($content, 'main page $content');
     $this->assertRaw($link1_shouldbe, t('URL displayed in Redirect mode.'), 'Basic');
 
-    // Check that the url is sucessfully stored in the database
-    $check = db_query("SELECT url FROM {weblinks} WHERE nid = :nid", array(':nid' => $link1->nid))->fetchField();
-    $this->assertEqual($link1->url, $check, t('URL for link1 is successfully stored.'), 'Basic');
-
-    // Let's look at the settings.
-    // First let's make sure the current user can't admin - test page 6.
-    $this->drupalGet('admin/config/content/weblinks');
-    $this->assertResponse(403, t('Access is denied on the administration page.'), 'Basic');
+    // Check that the fieldset for vocab 0 is collapsible and is collapsed.
+    $fieldset = $this->xpath('//fieldset[@id="weblinks-fieldset-0"]');
+    $fieldset_attributes = (array)$fieldset[0]->attributes();
+    $fieldset_class = $fieldset_attributes['@attributes']['class'];
+    debug($fieldset_class, '$fieldset_class');
+    $this->assertTrue(stristr($fieldset_class, 'collapsible'), 'The fieldset is collapsible.', 'Basic');
+    $this->assertTrue(stristr($fieldset_class, 'collapsed'), 'The fieldset is collapsed.', 'Basic');
 
-    // Prepare a user to do the stuff - test pages 7 to 10.
-    $user = $this->drupalCreateUser(array('access content', 'access web links', 'administer weblinks'));
-    $this->drupalLogin($user);
+    // Set the default to non-collapsible fieldsets.
+    $settings = array(
+      'weblinks_collapsible' => '0',
+    );
+    $this->drupalPost('admin/config/content/weblinks', $settings, t('Save configuration'));
 
-    // Make sure the hidden groups and settings tab do show up now - test page 11.
-    $this->drupalGet('weblinks');
+    $content = $this->drupalGet('weblinks');
+    // Check that the fieldset for vocab 0 is not collapsible and not collapsed.
+    $fieldset = $this->xpath('//fieldset[@id="weblinks-fieldset-0"]');
+    $fieldset_attributes = (array)$fieldset[0]->attributes();
+    $fieldset_class = $fieldset_attributes['@attributes']['class'];
+    debug($fieldset_class, '$fieldset_class');
+    $this->assertFalse(stristr($fieldset_class, 'collapsible'), 'The fieldset is not collapsible.', 'Basic');
+    $this->assertFalse(stristr($fieldset_class, 'collapsed'), 'The fieldset is not collapsed.', 'Basic');
+
+    // Make sure the hidden groups and settings tab show up.
     $this->assertText(t('Unclassified'), t('Unclassified group is displayed.'), 'Basic');
     $this->assertText(t('Unpublished'), t('Unpublished group is displayed.'), 'Basic');
     $this->assertText(t('Settings'), t('Settings tab is available.'), 'Basic');
     $this->assertText(t('Add a group'), t('Add Group tab is available.'), 'Basic');
 
-    // Check that the group settings page is accessible - test page 12.
+    // Check that the group settings page is accessible.
     $content = $this->drupalGet('admin/config/content/weblinks');
     //$this->pass(check_plain($content), 'admin/config/content/weblinks');
     $this->assertResponse(200, t('Access is granted on the administration page.'), 'Settings');
     $this->assertText('Description for unclassified links', t('Group settings includes "Unclassified".'), 'Settings');
 
-    // Checker settings should be turned off - test page 13.
+    // Checker settings should be turned off.
     $content = $this->drupalGet('admin/config/content/weblinks/checker');
     //$this->pass(check_plain($content), 'admin/config/content/weblinks/checker');
     $this->assertFieldByName('weblinks_checker_enabled', 0, t('Checker disabled.'), 'Settings');
diff --git a/weblinks.module b/weblinks.module
index 10b449d..fa5c499 100644
--- a/weblinks.module
+++ b/weblinks.module
@@ -1027,16 +1027,16 @@ function _weblinks_format_group($term, $tree) {
   foreach ($term->children as $child) {
     $data .= _weblinks_format_group($tree[$child], $tree);
   }
-  // Can't be collapsed if the title is empty.
   $fieldset = array(
     '#title' => $term->title . ' (' . $term->node_count . ')',
     '#id' => 'weblinks-fieldset-' . $term->tid,
-    '#collapsible' => $term->collapsible,
-    '#collapsed' => $term->collapsed,
     '#value' => $data,
-    '#attributes' => array('class' => array('collapsible')),
+    '#attributes' => array('class' => array(
+      $term->collapsible ? 'collapsible' : '',
+      $term->collapsed ? 'collapsed' : '',
+    )),
     '#children' => '',
-    );
+  );
   return '<div class="weblinkCat weblinkCat-depth-'. $term->depth .'">'. theme('fieldset', array('element' => $fieldset)) ."</div>\n";
 }
 
@@ -1144,7 +1144,7 @@ function weblinks_get_tree($parent = 0, $quick = FALSE) {
     // Collapsible is more complicated than just the setting.
     $new_tree[$tid]->collapsible = $collapsible && ($new_tree[$tid]->depth < $max_depth)  && !empty($term->name);
     $collapse_me = variable_get('weblinks_collapse_'. $tid, FALSE);
-    $new_tree[$tid]->collapsed = $collapsed || ($new_tree[$tid]->depth > $max_depth) || ($new_tree[$tid]->collapsible ? $collapse_me : FALSE);
+    $new_tree[$tid]->collapsed = $new_tree[$tid]->collapsible && ($collapsed || $collapse_me || ($new_tree[$tid]->depth > $max_depth));
 
     if ($new_tree[$tid]->collapsible) {
       $new_tree[$tid]->title = check_plain($term->name);
