Index: trunk/Mars/mcore/zfits.h
===================================================================
--- trunk/Mars/mcore/zfits.h	(revision 16815)
+++ trunk/Mars/mcore/zfits.h	(revision 16820)
@@ -168,5 +168,5 @@
     vector<char> fTransposedBuffer; ///<intermediate buffer to transpose the rows
     vector<char> fCompressedBuffer; ///<compressed rows
-    vector<char> fColumnOrdering; ///< ordering of the column's rows
+    vector<char> fColumnOrdering;   ///< ordering of the column's rows. Can change from tile to tile.
 
     size_t fNumTiles;       ///< Total number of tiles
@@ -180,4 +180,5 @@
     vector<vector<size_t> >                  fTileOffsets; ///< offset from start of tile of a given compressed column
 
+    // Get buffer space
     void AllocateBuffers()
     {
@@ -255,4 +256,5 @@
             clear(rdstate()|ios::badbit);
     }
+
     //overrides fits.h method with empty one
     //work is done in ReadBinaryRow because it requires volatile data from ReadBinaryRow
@@ -261,5 +263,6 @@
 
     }
-    // Compressed versin of the read row
+
+    // Compressed version of the read row
     bool ReadBinaryRow(const size_t &rowNum, char *bufferToRead)
     {
@@ -386,6 +389,7 @@
     }
 
+    // Apply the inverse transform of the integer smoothing
     uint32_t UnApplySMOOTHING(int16_t*   data,
-                              uint32_t numElems)
+                              uint32_t   numElems)
     {
         //un-do the integer smoothing
@@ -395,6 +399,8 @@
         return numElems*sizeof(uint16_t);
     }
+
     // Data has been read from disk. Uncompress it !
-    void UncompressBuffer(const uint32_t &catalogCurrentRow, const uint32_t &thisRoundNumRows)
+    void UncompressBuffer(const uint32_t &catalogCurrentRow,
+                          const uint32_t &thisRoundNumRows)
     {
         char *dest = fTransposedBuffer.data();
@@ -419,13 +425,12 @@
             const char *src = fCompressedBuffer.data()+compressedOffset+sizeof(BlockHeader)+sizeof(uint16_t)*head->numProcs;
 
-            for (uint32_t j=head->numProcs;j != 0; j--)
+            for (int32_t j=head->numProcs-1;j >= 0; j--)
             {
                 uint32_t sizeWritten=0;
 
-                switch (head->processings[j-1])
+                switch (head->processings[j])
                 {
                     case FACT_RAW:
-                            if (head->numProcs == 1)
-                                sizeWritten = UncompressUNCOMPRESSED(dest, src, numRows*numCols, col.size);
+                            sizeWritten = UncompressUNCOMPRESSED(dest, src, numRows*numCols, col.size);
                     break;
                     case FACT_SMOOTHING:
@@ -445,5 +450,5 @@
                 }
                 //increment destination counter only when processing done.
-                if (j==1) dest+= sizeWritten;
+                if (j==0) dest+= sizeWritten;
             }
         }
