diff --git a/treeplayer/inc/TTreeFormula.h b/treeplayer/inc/TTreeFormula.h
index a8850abd3c341a4263b530558325beacd5cf1f48..6734c6b9c48054b7705044f44a31dd30fcaa36d5 100644
--- a/treeplayer/inc/TTreeFormula.h
+++ b/treeplayer/inc/TTreeFormula.h
@@ -1,4 +1,4 @@
-// @(#)root/treeplayer:$Name:  $:$Id: TTreeFormula.h,v 1.38 2004/08/12 04:33:45 brun Exp $
+// @(#)root/treeplayer:$Name:  $:$Id: TTreeFormula.h,v 1.39 2004/10/05 13:21:10 brun Exp $
 // Author: Rene Brun   19/01/96
 
 /*************************************************************************
@@ -75,6 +75,7 @@ protected:
    TObjArray   fMethods;          //!  List of leaf method calls
    TObjArray   fAliases;          //!  List of TTreeFormula for each alias used.
    TObjArray   fLeafNames;        //   List of TNamed describing leaves
+   TObjArray   fBranches;         //!  List of branches to read.  Similar to fLeaces but duplicates are zeroed out.
 
    Int_t         fNdimensions[kMAXCODES];              //Number of array dimensions in each leaf
    Int_t         fFixedSizes[kMAXCODES][kMAXFORMDIM];  //Physical sizes of lower dimensions for each leaf
diff --git a/treeplayer/src/TTreeFormula.cxx b/treeplayer/src/TTreeFormula.cxx
index fac02e78ccd3c211eaf85555bc0b3cddcacb1cd9..160cf0cc6db0811381831bd98f6a590cb9e4869e 100644
--- a/treeplayer/src/TTreeFormula.cxx
+++ b/treeplayer/src/TTreeFormula.cxx
@@ -1,4 +1,4 @@
-// @(#)root/treeplayer:$Name:  $:$Id: TTreeFormula.cxx,v 1.160 2005/01/13 20:07:46 brun Exp $
+// @(#)root/treeplayer:$Name:  $:$Id: TTreeFormula.cxx,v 1.161 2005/01/19 07:52:45 brun Exp $
 // Author: Rene Brun   19/01/96
 
 /*************************************************************************
@@ -231,7 +231,16 @@ TTreeFormula::TTreeFormula(const char *name,const char *expression, TTree *tree)
       }
    }
 
-
+   // Create a list of uniques branches to load.
+   for(k=0; k<fNcodes; k++) {
+      TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(k);
+      TBranch *branch = 0;
+      if (leaf) {
+         branch = leaf->GetBranch();
+         if (fBranches.FindObject(branch)) branch = 0;
+      }
+      fBranches.AddAtAndExpand(branch,k);
+   }
 }
 
 //______________________________________________________________________________
@@ -2646,8 +2655,15 @@ const char* TTreeFormula::EvalStringInstance(Int_t instance)
    /* Now let calculate what physical instance we really need.  */                              \
    const Int_t real_instance = GetRealInstance(instance,code);                                  \
                                                                                                 \
-   if (!instance) leaf->GetBranch()->GetEntry(leaf->GetBranch()->GetTree()->GetReadEntry());    \
-   else {                                                                                       \
+   if (!instance) {                                                                             \
+        TBranch *branch = (TBranch*)fBranches.UncheckedAt(code);                                \
+        if (branch) branch->GetEntry(branch->GetTree()->GetReadEntry());                        \
+        else if (fDidBooleanOptimization) {                                                     \
+           branch = leaf->GetBranch();                                                          \
+           Long64_t treeEntry = branch->GetTree()->GetReadEntry();                              \
+           if (branch->GetReadEntry() != treeEntry) branch->GetEntry( treeEntry );              \
+        }                                                                                       \
+   } else {                                                                                     \
       /* In the cases where we are behind (i.e. right of) a potential boolean optimization      \
          this tree variable reading may have not been executed with instance==0 which would     \
          result in the branch being potentially not read in. */                                 \
@@ -3490,6 +3506,7 @@ void TTreeFormula::UpdateFormulaLeaves()
       sprintf(names,"%s/%s",fLeafNames[i]->GetTitle(),fLeafNames[i]->GetName());
       TLeaf *leaf = fTree->GetLeaf(names);
       fLeaves[i] = leaf;
+      if (fBranches[i]) fBranches[i]=leaf->GetBranch();
    }
    for (Int_t j=0; j<kMAXCODES; j++) {
       for (Int_t k = 0; k<kMAXFORMDIM; k++) {
diff --git a/treeplayer/src/TTreeIndex.cxx b/treeplayer/src/TTreeIndex.cxx
index f802cfcd28140bfe2914e2c726ffa1a99c23ac0c..f18b613d5a86f53dc6d0437bf005c900a0c73bc4 100644
--- a/treeplayer/src/TTreeIndex.cxx
+++ b/treeplayer/src/TTreeIndex.cxx
@@ -1,4 +1,4 @@
-// @(#)root/tree:$Name:  $:$Id: TTreeIndex.cxx,v 1.6 2004/07/19 19:48:47 brun Exp $
+// @(#)root/tree:$Name:  $:$Id: TTreeIndex.cxx,v 1.7 2004/12/08 10:15:30 brun Exp $
 // Author: Rene Brun   05/07/2004
 
 /*************************************************************************
@@ -135,8 +135,9 @@ TTreeIndex::TTreeIndex(const TTree *T, const char *majorname, const char *minorn
 
    Long64_t *w = new Long64_t[fN];
    Long64_t i;
+   Long64_t oldEntry = fTree->GetReadEntry();
    for (i=0;i<fN;i++) {
-      GetEntry(i);
+      fTree->LoadTree(i);
       Double_t majord = fMajorFormula->EvalInstance();
       Double_t minord = fMinorFormula->EvalInstance();
       Long64_t majorv = (Long64_t)majord;
@@ -152,6 +153,7 @@ TTreeIndex::TTreeIndex(const TTree *T, const char *majorname, const char *minorn
    }
 
    delete [] w;
+   fTree->LoadTree(oldEntry);
 }
 
 //______________________________________________________________________________
@@ -326,15 +328,15 @@ void TTreeIndex::Print(Option_t * option) const
    if (opt.Contains("100"))  n = 100;
    if (opt.Contains("1000")) n = 1000;
 
-   printf("\n**********************************************\n");
-   printf("*    Index of Tree: %s/%s\n",fTree->GetName(),fTree->GetTitle());
-   printf("**********************************************\n");
-   printf("%8s : %16s : %16s\n","serial",fMajorName.Data(),fMinorName.Data());
-   printf("**********************************************\n");
+   Printf("\n**********************************************");
+   Printf("*    Index of Tree: %s/%s",fTree->GetName(),fTree->GetTitle());
+   Printf("**********************************************");
+   Printf("%8s : %16s : %16s","serial",fMajorName.Data(),fMinorName.Data());
+   Printf("**********************************************");
    for (Long64_t i=0;i<n;i++) {
       Long64_t minor = fIndexValues[i] & 0xffff;
       Long64_t major = fIndexValues[i]>>31;
-      printf("%8lld :         %8lld :         %8lld\n",i,major,minor);
+      Printf("%8lld :         %8lld :         %8lld",i,major,minor);
    }
 }