Index: trunk/ippScripts/scripts/magic_tree.pl
===================================================================
--- trunk/ippScripts/scripts/magic_tree.pl	(revision 20674)
+++ trunk/ippScripts/scripts/magic_tree.pl	(revision 20762)
@@ -167,6 +167,10 @@
 #    my $naxis1 = $$header{'NAXIS1'} or &my_die("Can't find NAXIS1", $magic_id, $PS_EXIT_SYS_ERROR);
     my $naxis1 = $$header{'NAXIS1'};
-    if (!$naxis1) {
-        # XXX: if the skyfile is compressed then the WCS won't be in the primary header
+    my $naxis2;
+    if ($naxis1) {
+        $naxis2 = $$header{'NAXIS2'} or &my_die("Can't find NAXIS2", $magic_id, $PS_EXIT_SYS_ERROR);
+    } else {
+        # if the skyfile is compressed then the WCS won't be in the primary header, move to the 
+        # extension
         my $hdutype;
         $fits->movrel_hdu(1, $hdutype, $status);
@@ -175,7 +179,9 @@
         ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $fits );
         &my_die("Unable to read extension header: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
-        $naxis1 = $$header{'NAXIS1'} or &my_die("Can't find NAXIS1", $magic_id, $PS_EXIT_SYS_ERROR);
-    }
-    my $naxis2 = $$header{'NAXIS2'} or &my_die("Can't find NAXIS2", $magic_id, $PS_EXIT_SYS_ERROR);
+        my $xtension = $$header{'XTENSION'} or &my_die("Can't find XTENSION", $magic_id, $PS_EXIT_SYS_ERROR);
+        &my_die("XTENSION found: $xtension", $magic_id, $PS_EXIT_SYS_ERROR) if $xtension ne "'BINTABLE'";
+        $naxis1 = $$header{'ZNAXIS1'} or &my_die("Can't find ZNAXIS1", $magic_id, $PS_EXIT_SYS_ERROR);
+        $naxis2 = $$header{'ZNAXIS2'} or &my_die("Can't find ZNAXIS2", $magic_id, $PS_EXIT_SYS_ERROR);
+    }
     my $ctype1 = $$header{'CTYPE1'} or &my_die("Can't find CTYPE1", $magic_id, $PS_EXIT_SYS_ERROR);
     my $ctype2 = $$header{'CTYPE2'} or &my_die("Can't find CTYPE2", $magic_id, $PS_EXIT_SYS_ERROR);
@@ -347,4 +353,9 @@
     my $contents = $node->{contents} or die "Can't find contents of node."; # Contents of node
 
+    if ($position eq 'root' and scalar @$contents <= 4) {
+        # don't need to divide, but do we need to sort?
+        return;
+    }
+
     my ($lower, $upper) = divide_list($contents, 'xi');
 
