shallow code cleanup for btrees while cataloging todos

git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_lsm_tree@1737 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeFrame.java
index cfa622d..b0fd2d8 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeFrame.java
@@ -18,13 +18,15 @@
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrame;
 import edu.uci.ics.hyracks.storage.am.common.api.TreeIndexException;
-import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
 
 public interface IBTreeFrame extends ITreeIndexFrame {
-	public int findUpdateTupleIndex(ITupleReference tuple) throws TreeIndexException;
-	public int findInsertTupleIndex(ITupleReference tuple) throws TreeIndexException;	
-	public int findDeleteTupleIndex(ITupleReference tuple) throws TreeIndexException;
-	public void insertSorted(ITupleReference tuple);
-    public boolean getSmFlag();
+    public int findInsertTupleIndex(ITupleReference tuple) throws TreeIndexException;
+
+    public int findDeleteTupleIndex(ITupleReference tuple) throws TreeIndexException;
+
+    public void insertSorted(ITupleReference tuple);
+
     public void setSmFlag(boolean smFlag);
+
+    public boolean getSmFlag();
 }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeLeafFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeLeafFrame.java
index 427ab9a..bbb67bd 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeLeafFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeLeafFrame.java
@@ -24,13 +24,21 @@
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
 
 public interface IBTreeLeafFrame extends IBTreeFrame {
+    public int findTupleIndex(ITupleReference searchKey, ITreeIndexTupleReference pageTuple, MultiComparator cmp,
+            FindTupleMode ftm, FindTupleNoExactMatchPolicy ftp) throws HyracksDataException;
+
+    public int findUpdateTupleIndex(ITupleReference tuple) throws TreeIndexException;
+
+    public int findUpsertTupleIndex(ITupleReference tuple) throws TreeIndexException;
+
+    /**
+     * @param searchTuple the tuple to match 
+     * @param targetTupleIndex the index of the tuple to check
+     * @return the tuple at targetTupleIndex if its keys match searchTuple's keys, otherwise null 
+     */
+    public ITupleReference getMatchingKeyTuple(ITupleReference searchTuple, int targetTupleIndex);
+
     public void setNextLeaf(int nextPage);
 
     public int getNextLeaf();
-
-    public int findTupleIndex(ITupleReference searchKey, ITreeIndexTupleReference pageTuple, MultiComparator cmp,
-            FindTupleMode ftm, FindTupleNoExactMatchPolicy ftp) throws HyracksDataException;
-    
-    public int findUpsertTupleIndex(ITupleReference tuple) throws TreeIndexException;
-    public ITupleReference getBeforeTuple(ITupleReference tuple, int targetTupleIndex) throws TreeIndexException;
 }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IPrefixSlotManager.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IPrefixSlotManager.java
index 0636968..6ec5eef 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IPrefixSlotManager.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IPrefixSlotManager.java
@@ -22,29 +22,28 @@
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.FindTupleNoExactMatchPolicy;
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
 
-// a slot consists of two fields:
-// first field is 1 byte, it indicates the slot number of a prefix tuple
-// we call the first field prefixSlotOff
-// second field is 3 bytes, it points to the start offset of a tuple
-// we call the second field tupleOff
-
-// we distinguish between two slot types:
-// prefix slots that point to prefix tuples, 
-// a frame is assumed to have a field numPrefixTuples
-// tuple slots that point to data tuples
-// a frame is assumed to have a field numTuples
-// a tuple slot contains a tuple pointer and a pointer to a prefix slot (prefix slot number) 
-
-// INSERT procedure
-// a tuple insertion may use an existing prefix tuple 
-// a tuple insertion may never create a new prefix tuple
-// modifying the prefix slots would be extremely expensive because: 
-// potentially all tuples slots would have to change their prefix slot pointers
-// all prefixes are recomputed during a reorg or compaction
-
+/**
+ *  A slot consists of two fields. The first field is 1 byte and it indicates the slot number of 
+ *  a prefix tuple that is called the first field prefixSlotOff. The second field is 3 bytes and 
+ *  it points to the start offset of a tuple that is called the second field tupleOff.
+ *  
+ *  We distinguish between two slot types:
+ *      1) prefix slots that point to prefix tuples (a frame is assumed to have a field numPrefixTuples)
+ *      2) tuple slots that point to data tuples (a frame is assumed to have a field numTuples)
+ *      
+ *  A tuple slot contains a tuple pointer and a pointer to a prefix slot (prefix slot number).
+ *  
+ *  INSERT procedure:
+ *      - A tuple insertion may use an existing prefix tuple
+ *      - A tuple insertion may never create a new prefix tuple
+ *  
+ *  Modifying the prefix slots would be extremely expensive because potentially all tuples slots 
+ *  would have to change their prefix slot pointers. All prefixes are recomputed during a reorg 
+ *  or compaction.
+ */
 public interface IPrefixSlotManager extends ISlotManager {
     // TODO: Clean up interface after extending ISlotManager.
-	
+
     public int decodeFirstSlotField(int slot);
 
     public int decodeSecondSlotField(int slot);
@@ -57,7 +56,9 @@
 
     public int insertSlot(int slot, int tupleOff);
 
-    // returns prefix slot number, returns TUPLE_UNCOMPRESSED if none found
+    /** 
+     * @return the prefix slot number or FieldPrefixSlotManager.TUPLE_UNCOMPRESSED if none found
+     */
     public int findPrefix(ITupleReference tuple, ITreeIndexTupleReference framePrefixTuple);
 
     public int getTupleSlotStartOff();
@@ -78,6 +79,6 @@
 
     // functions for testing
     public void setPrefixSlot(int tupleIndex, int slot);
-    
+
     public void setMultiComparator(MultiComparator cmp);
 }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/ITupleAcceptor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/ITupleAcceptor.java
index 1e2b623..5f4b30a 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/ITupleAcceptor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/ITupleAcceptor.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.hyracks.storage.am.btree.api;
 
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/compressors/FieldPrefixCompressor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/compressors/FieldPrefixCompressor.java
index f78b6e4..7e27113 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/compressors/FieldPrefixCompressor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/compressors/FieldPrefixCompressor.java
@@ -33,15 +33,13 @@
 
 public class FieldPrefixCompressor implements ITreeIndexFrameCompressor {
 
-    // minimum ratio of uncompressed tuples to total tuple to consider
-    // re-compression
-    private float ratioThreshold;
+    // minimum ratio of uncompressed tuples to total tuple to consider re-compression
+    private final float ratioThreshold;
 
-    // minimum number of tuple matching field prefixes to consider compressing
-    // them
-    private int occurrenceThreshold;
+    // minimum number of tuple matching field prefixes to consider compressing them
+    private final int occurrenceThreshold;
 
-    private ITypeTraits[] typeTraits;
+    private final ITypeTraits[] typeTraits;
 
     public FieldPrefixCompressor(ITypeTraits[] typeTraits, float ratioThreshold, int occurrenceThreshold) {
         this.typeTraits = typeTraits;
@@ -51,8 +49,8 @@
 
     @Override
     public boolean compress(ITreeIndexFrame indexFrame, MultiComparator cmp) throws Exception {
-        BTreeFieldPrefixNSMLeafFrame frame = (BTreeFieldPrefixNSMLeafFrame)indexFrame;
-    	int tupleCount = frame.getTupleCount();
+        BTreeFieldPrefixNSMLeafFrame frame = (BTreeFieldPrefixNSMLeafFrame) indexFrame;
+        int tupleCount = frame.getTupleCount();
         if (tupleCount <= 0) {
             frame.setPrefixTupleCount(0);
             frame.setFreeSpaceOff(frame.getOrigFreeSpaceOff());
@@ -63,7 +61,7 @@
         if (cmp.getKeyFieldCount() == 1) {
             return false;
         }
-        
+
         int uncompressedTupleCount = frame.getUncompressedTupleCount();
         float ratio = (float) uncompressedTupleCount / (float) tupleCount;
         if (ratio < ratioThreshold)
@@ -74,7 +72,7 @@
 
         ByteBuffer buf = frame.getBuffer();
         byte[] pageArray = buf.array();
-        IPrefixSlotManager slotManager = frame.slotManager;
+        IPrefixSlotManager slotManager = (IPrefixSlotManager) frame.getSlotManager();
 
         // perform analysis pass
         ArrayList<KeyPartition> keyPartitions = getKeyPartitions(frame, cmp, occurrenceThreshold);
@@ -95,8 +93,7 @@
                 }
             }
 
-            // ignore keyPartitions with no benefit and don't count bytes and
-            // slots needed
+            // ignore keyPartitions with no benefit and don't count bytes and slots needed
             if (kp.maxBenefitMinusCost <= 0)
                 continue;
 
@@ -104,12 +101,9 @@
             totalSlotsNeeded += kp.pmi[kp.maxPmiIndex].prefixSlotsNeeded;
         }
 
-        // System.out.println("TOTAL SLOTS NEEDED: " + totalSlotsNeeded);
-
         // we use a greedy heuristic to solve this "knapsack"-like problem
         // (every keyPartition has a space savings and a number of slots
-        // required, but the number of slots are constrained by
-        // MAX_PREFIX_SLOTS)
+        // required, but the number of slots are constrained by MAX_PREFIX_SLOTS)
         // we sort the keyPartitions by maxBenefitMinusCost / prefixSlotsNeeded
         // and later choose the top MAX_PREFIX_SLOTS
         int[] newPrefixSlots;
@@ -139,8 +133,7 @@
                 keyPartitions.remove(lastIndex);
             }
 
-            // re-order keyPartitions by prefix (corresponding to original
-            // order)
+            // re-order keyPartitions by prefix (corresponding to original order)
             SortByOriginalRank originalRankComparator = new SortByOriginalRank();
             Collections.sort(keyPartitions, originalRankComparator);
         } else {
@@ -150,8 +143,7 @@
         int[] newTupleSlots = new int[tupleCount];
 
         // WARNING: our hope is that compression is infrequent
-        // here we allocate a big chunk of memory to temporary hold the new,
-        // re-compressed tuple
+        // here we allocate a big chunk of memory to temporary hold the new, re-compressed tuple
         // in general it is very hard to avoid this step
         int prefixFreeSpace = frame.getOrigFreeSpaceOff();
         int tupleFreeSpace = prefixFreeSpace + totalPrefixBytes;
@@ -159,8 +151,8 @@
         ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
 
         // perform compression, and reorg
-        // we assume that the keyPartitions are sorted by the prefixes (i.e., in
-        // the logical target order)
+        // we assume that the keyPartitions are sorted by the prefixes 
+        // (i.e., in the logical target order)
         int kpIndex = 0;
         int tupleIndex = 0;
         int prefixTupleIndex = 0;
@@ -176,19 +168,13 @@
                 // beginning of keyPartition found, compress entire keyPartition
                 if (tupleIndex == keyPartitions.get(kpIndex).firstTupleIndex) {
 
-                    // number of fields we decided to use for compression of
-                    // this keyPartition
+                    // number of fields we decided to use for compression of this keyPartition
                     int fieldCountToCompress = keyPartitions.get(kpIndex).maxPmiIndex + 1;
                     int segmentStart = keyPartitions.get(kpIndex).firstTupleIndex;
                     int tuplesInSegment = 1;
 
-                    // System.out.println("PROCESSING KEYPARTITION: " + kpIndex
-                    // + " RANGE: " + keyPartitions.get(kpIndex).firstRecSlotNum
-                    // + " " + keyPartitions.get(kpIndex).lastRecSlotNum +
-                    // " FIELDSTOCOMPRESS: " + fieldCountToCompress);
-
-                    FieldPrefixTupleReference prevTuple = new FieldPrefixTupleReference(tupleWriter
-                            .createTupleReference());
+                    FieldPrefixTupleReference prevTuple = new FieldPrefixTupleReference(
+                            tupleWriter.createTupleReference());
                     prevTuple.setFieldCount(fieldCount);
 
                     FieldPrefixTupleReference tuple = new FieldPrefixTupleReference(tupleWriter.createTupleReference());
@@ -198,8 +184,7 @@
                         prevTuple.resetByTupleIndex(frame, i - 1);
                         tuple.resetByTupleIndex(frame, i);
 
-                        // check if tuples match in fieldCountToCompress of their
-                        // first fields
+                        // check if tuples match in fieldCountToCompress of their first fields
                         int prefixFieldsMatch = 0;
                         for (int j = 0; j < fieldCountToCompress; j++) {
                             if (cmps[j].compare(pageArray, prevTuple.getFieldStart(j), prevTuple.getFieldLength(j),
@@ -209,8 +194,8 @@
                                 break;
                         }
 
-                        // the two tuples must match in exactly the number of
-                        // fields we decided to compress for this keyPartition
+                        // the two tuples must match in exactly the number of fields we decided 
+                        // to compress for this keyPartition
                         int processSegments = 0;
                         if (prefixFieldsMatch == fieldCountToCompress)
                             tuplesInSegment++;
@@ -221,12 +206,10 @@
                             processSegments++;
 
                         for (int r = 0; r < processSegments; r++) {
-                            // compress current segment and then start new
-                            // segment
+                            // compress current segment and then start new segment
                             if (tuplesInSegment < occurrenceThreshold || fieldCountToCompress <= 0) {
-                                // segment does not have at least
-                                // occurrenceThreshold tuples, so write tuples
-                                // uncompressed
+                                // segment does not have at least occurrenceThreshold tuples, so 
+                                // write tuples uncompressed
                                 for (int j = 0; j < tuplesInSegment; j++) {
                                     int slotNum = segmentStart + j;
                                     tupleToWrite.resetByTupleIndex(frame, slotNum);
@@ -236,29 +219,14 @@
                                 }
                                 uncompressedTupleCount += tuplesInSegment;
                             } else {
-                                // segment has enough tuples, compress segment
-                                // extract prefix, write prefix tuple to buffer,
-                                // and set prefix slot
+                                // segment has enough tuples: compress segment, extract prefix, 
+                                // write prefix tuple to buffer, and set prefix slot
                                 newPrefixSlots[newPrefixSlots.length - 1 - prefixTupleIndex] = slotManager
                                         .encodeSlotFields(fieldCountToCompress, prefixFreeSpace);
-                                // int tmp = freeSpace;
-                                // prevRec.reset();
-                                // System.out.println("SOURCE CONTENTS: " +
-                                // buf.getInt(prevRec.getFieldOff()) + " " +
-                                // buf.getInt(prevRec.getFieldOff()+4));
                                 prefixFreeSpace += tupleWriter.writeTupleFields(prevTuple, 0, fieldCountToCompress,
                                         byteBuffer.array(), prefixFreeSpace);
-                                // System.out.println("WRITING PREFIX RECORD " +
-                                // prefixSlotNum + " AT " + tmp + " " +
-                                // freeSpace);
-                                // System.out.print("CONTENTS: ");
-                                // for(int x = 0; x < fieldCountToCompress; x++)
-                                // System.out.print(buf.getInt(tmp + x*4) +
-                                // " ");
-                                // System.out.println();
 
-                                // truncate tuples, write them to buffer, and
-                                // set tuple slots
+                                // truncate tuples, write them to buffer, and set tuple slots
                                 for (int j = 0; j < tuplesInSegment; j++) {
                                     int currTupleIndex = segmentStart + j;
                                     tupleToWrite.resetByTupleIndex(frame, currTupleIndex);
@@ -298,27 +266,24 @@
             tupleIndex++;
         }
 
-        // sanity check to see if we have written exactly as many prefix bytes
-        // as computed before
+        // sanity check to see if we have written exactly as many prefix bytes as computed before
         if (prefixFreeSpace != frame.getOrigFreeSpaceOff() + totalPrefixBytes) {
             throw new Exception("ERROR: Number of prefix bytes written don't match computed number");
         }
 
-        // in some rare instances our procedure could even increase the space
-        // requirement which is very dangerous
-        // this can happen to to the greedy solution of the knapsack-like
-        // problem
-        // therefore, we check if the new space exceeds the page size to avoid
-        // the only danger of an increasing space
+        // in some rare instances our procedure could even increase the space requirement which is very dangerous
+        // this can happen to to the greedy solution of the knapsack-like problem
+        // therefore, we check if the new space exceeds the page size to avoid the only danger of 
+        // an increasing space
         int totalSpace = tupleFreeSpace + newTupleSlots.length * slotManager.getSlotSize() + newPrefixSlots.length
                 * slotManager.getSlotSize();
         if (totalSpace > buf.capacity())
-            return false; // just leave the page as is
+            // just leave the page as is
+            return false;
 
         // copy new tuple and new slots into original page
         int freeSpaceAfterInit = frame.getOrigFreeSpaceOff();
-        System.arraycopy(buffer, freeSpaceAfterInit, pageArray, freeSpaceAfterInit, tupleFreeSpace
-                        - freeSpaceAfterInit);
+        System.arraycopy(buffer, freeSpaceAfterInit, pageArray, freeSpaceAfterInit, tupleFreeSpace - freeSpaceAfterInit);
 
         // copy prefix slots
         int slotOffRunner = buf.capacity() - slotManager.getSlotSize();
@@ -333,22 +298,6 @@
             slotOffRunner -= slotManager.getSlotSize();
         }
 
-        // int originalFreeSpaceOff = frame.getOrigFreeSpaceOff();
-        // System.out.println("ORIGINALFREESPACE: " + originalFreeSpaceOff);
-        // System.out.println("RECSPACE BEF: " + (frame.getFreeSpaceOff() -
-        // originalFreeSpaceOff));
-        // System.out.println("RECSPACE AFT: " + (recordFreeSpace -
-        // originalFreeSpaceOff));
-        // System.out.println("PREFIXSLOTS BEF: " +
-        // frame.getNumPrefixRecords());
-        // System.out.println("PREFIXSLOTS AFT: " + newPrefixSlots.length);
-        //        
-        // System.out.println("FREESPACE BEF: " + frame.getFreeSpaceOff());
-        // System.out.println("FREESPACE AFT: " + recordFreeSpace);
-        // System.out.println("PREFIXES: " + newPrefixSlots.length + " / " +
-        // FieldPrefixSlotManager.MAX_PREFIX_SLOTS);
-        // System.out.println("RECORDS: " + newRecordSlots.length);
-
         // update space fields, TODO: we need to update more fields
         frame.setFreeSpaceOff(tupleFreeSpace);
         frame.setPrefixTupleCount(newPrefixSlots.length);
@@ -377,7 +326,7 @@
         int maxCmps = cmps.length - 1;
         ByteBuffer buf = frame.getBuffer();
         byte[] pageArray = buf.array();
-        IPrefixSlotManager slotManager = frame.slotManager;
+        IPrefixSlotManager slotManager = (IPrefixSlotManager) frame.getSlotManager();
 
         ArrayList<KeyPartition> keyPartitions = new ArrayList<KeyPartition>();
         KeyPartition kp = new KeyPartition(maxCmps);
@@ -397,10 +346,6 @@
             prevTuple.resetByTupleIndex(frame, i - 1);
             tuple.resetByTupleIndex(frame, i);
 
-            // System.out.println("BEFORE RECORD: " + i + " " + rec.recSlotOff +
-            // " " + rec.recOff);
-            // kp.print();
-
             int prefixFieldsMatch = 0;
             for (int j = 0; j < maxCmps; j++) {
 
@@ -415,16 +360,15 @@
                                     - prefixFieldsMatch);
 
                     if (kp.pmi[j].matches == occurrenceThreshold) {
-                        // if we compress this prefix, we pay the cost of
-                        // storing it once, plus the size for one prefix slot
+                        // if we compress this prefix, we pay the cost of storing it once, plus 
+                        // the size for one prefix slot
                         kp.pmi[j].prefixBytes += prefixBytes;
                         kp.pmi[j].spaceCost += prefixBytes + slotManager.getSlotSize();
                         kp.pmi[j].prefixSlotsNeeded++;
                         kp.pmi[j].spaceBenefit += occurrenceThreshold * spaceBenefit;
                     } else if (kp.pmi[j].matches > occurrenceThreshold) {
-                        // we are beyond the occurrence threshold, every
-                        // additional tuple with a matching prefix increases the
-                        // benefit
+                        // we are beyond the occurrence threshold, every additional tuple with a 
+                        // matching prefix increases the benefit
                         kp.pmi[j].spaceBenefit += spaceBenefit;
                     }
                 } else {
@@ -433,15 +377,8 @@
                 }
             }
 
-            // System.out.println();
-            // System.out.println("AFTER RECORD: " + i);
-            // kp.print();
-            // System.out.println("-----------------");
-
-            // this means not even the first field matched, so we start to
-            // consider a new "key partition"
+            // this means not even the first field matched, so we start to consider a new "key partition"
             if (maxCmps > 0 && prefixFieldsMatch == 0) {
-                // System.out.println("NEW KEY PARTITION");
                 kp.lastTupleIndex = i - 1;
 
                 // remove keyPartitions that don't have enough tuples
@@ -478,7 +415,6 @@
         public int maxPmiIndex = -1;
 
         // number of fields used for compression for this kp of current page
-
         public KeyPartition(int numKeyFields) {
             pmi = new PrefixMatchInfo[numKeyFields];
             for (int i = 0; i < numKeyFields; i++) {
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorDescriptor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorDescriptor.java
index 4df9ea6..33aaed1 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorDescriptor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorDescriptor.java
@@ -33,12 +33,10 @@
 
     private static final long serialVersionUID = 1L;
 
-    // fields in input tuple to be used as low keys
-    protected int[] lowKeyFields;
-    // fields in input tuple to be used as high keys
-    protected int[] highKeyFields;
-    protected boolean lowKeyInclusive;
-    protected boolean highKeyInclusive;
+    protected final int[] lowKeyFields;
+    protected final int[] highKeyFields;
+    protected final boolean lowKeyInclusive;
+    protected final boolean highKeyInclusive;
 
     public BTreeSearchOperatorDescriptor(IOperatorDescriptorRegistry spec, RecordDescriptor recDesc,
             IStorageManagerInterface storageManager, IIndexLifecycleManagerProvider lifecycleManagerProvider,
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java
index b284847..65b9a33 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java
@@ -25,10 +25,11 @@
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
 
 public class BTreeSearchOperatorNodePushable extends TreeIndexSearchOperatorNodePushable {
+    protected final boolean lowKeyInclusive;
+    protected final boolean highKeyInclusive;
+
     protected PermutingFrameTupleReference lowKey;
     protected PermutingFrameTupleReference highKey;
-    protected boolean lowKeyInclusive;
-    protected boolean highKeyInclusive;
     protected MultiComparator lowKeySearchCmp;
     protected MultiComparator highKeySearchCmp;
 
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeUpdateSearchOperatorNodePushable.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeUpdateSearchOperatorNodePushable.java
index 1141639..22e95b2 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeUpdateSearchOperatorNodePushable.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeUpdateSearchOperatorNodePushable.java
@@ -47,9 +47,9 @@
             tb.reset();
             cursor.next();
             if (retainInput) {
-            	frameTuple.reset(accessor, tupleIndex);
+                frameTuple.reset(accessor, tupleIndex);
                 for (int i = 0; i < frameTuple.getFieldCount(); i++) {
-                	dos.write(frameTuple.getFieldData(i), frameTuple.getFieldStart(i), frameTuple.getFieldLength(i));
+                    dos.write(frameTuple.getFieldData(i), frameTuple.getFieldStart(i), frameTuple.getFieldLength(i));
                     tb.addFieldEndOffset();
                 }
             }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeDuplicateKeyException.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeDuplicateKeyException.java
index d6d945f..5a1d610 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeDuplicateKeyException.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeDuplicateKeyException.java
@@ -17,11 +17,11 @@
 
 public class BTreeDuplicateKeyException extends BTreeException {
     private static final long serialVersionUID = 1L;
-    
+
     public BTreeDuplicateKeyException(Exception e) {
         super(e);
     }
-    
+
     public BTreeDuplicateKeyException(String message) {
         super(message);
     }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeNonExistentKeyException.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeNonExistentKeyException.java
index 81a0e79..989f118 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeNonExistentKeyException.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeNonExistentKeyException.java
@@ -16,13 +16,13 @@
 package edu.uci.ics.hyracks.storage.am.btree.exceptions;
 
 public class BTreeNonExistentKeyException extends BTreeException {
-    
+
     private static final long serialVersionUID = 1L;
-    
+
     public BTreeNonExistentKeyException(Exception e) {
         super(e);
     }
-    
+
     public BTreeNonExistentKeyException(String message) {
         super(message);
     }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeNotUpdateableException.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeNotUpdateableException.java
index 73b22d8..7e83c69 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeNotUpdateableException.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/exceptions/BTreeNotUpdateableException.java
@@ -17,11 +17,11 @@
 
 public class BTreeNotUpdateableException extends BTreeException {
     private static final long serialVersionUID = 1L;
-    
+
     public BTreeNotUpdateableException(Exception e) {
         super(e);
     }
-    
+
     public BTreeNotUpdateableException(String message) {
         super(message);
     }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrame.java
index e8a342d..9fadad5 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrame.java
@@ -30,7 +30,6 @@
 import edu.uci.ics.hyracks.storage.am.btree.impls.FieldPrefixPrefixTupleReference;
 import edu.uci.ics.hyracks.storage.am.btree.impls.FieldPrefixSlotManager;
 import edu.uci.ics.hyracks.storage.am.btree.impls.FieldPrefixTupleReference;
-import edu.uci.ics.hyracks.storage.am.common.api.ISlotManager;
 import edu.uci.ics.hyracks.storage.am.common.api.ISplitKey;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrame;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrameCompressor;
@@ -45,8 +44,9 @@
 import edu.uci.ics.hyracks.storage.am.common.tuples.TypeAwareTupleWriter;
 import edu.uci.ics.hyracks.storage.common.buffercache.ICachedPage;
 
-// WARNING: only works when tupleWriter is an instance of TypeAwareTupleWriter
-
+/**
+ * WARNING: only works when tupleWriter is an instance of TypeAwareTupleWriter
+ */
 public class BTreeFieldPrefixNSMLeafFrame implements IBTreeLeafFrame {
 
     protected static final int pageLsnOff = 0; // 0
@@ -57,28 +57,26 @@
     protected static final int smFlagOff = levelOff + 1; // 21
     protected static final int uncompressedTupleCountOff = smFlagOff + 1; // 22
     protected static final int prefixTupleCountOff = uncompressedTupleCountOff + 4; // 26
-
     protected static final int nextLeafOff = prefixTupleCountOff + 4; // 30
 
+    private final IPrefixSlotManager slotManager;
+    private final ITreeIndexFrameCompressor compressor;
+    private final FieldPrefixTupleReference frameTuple;
+    private final FieldPrefixPrefixTupleReference framePrefixTuple;
+    private final ITreeIndexTupleWriter tupleWriter;
+
+    private MultiComparator cmp;
+
     protected ICachedPage page = null;
     protected ByteBuffer buf = null;
 
-    public final ITreeIndexFrameCompressor compressor;
-    // TODO: Should be protected, but will trigger some refactoring.
-    public final IPrefixSlotManager slotManager;
-
-    private final ITreeIndexTupleWriter tupleWriter;
-    private MultiComparator cmp;
-
-    private final FieldPrefixTupleReference frameTuple;
-    private final FieldPrefixPrefixTupleReference framePrefixTuple;
-
     public BTreeFieldPrefixNSMLeafFrame(ITreeIndexTupleWriter tupleWriter) {
         this.tupleWriter = tupleWriter;
         this.frameTuple = new FieldPrefixTupleReference(tupleWriter.createTupleReference());
+        this.slotManager = new FieldPrefixSlotManager();
+
         ITypeTraits[] typeTraits = ((TypeAwareTupleWriter) tupleWriter).getTypeTraits();
         this.framePrefixTuple = new FieldPrefixPrefixTupleReference(typeTraits);
-        this.slotManager = new FieldPrefixSlotManager();
         this.compressor = new FieldPrefixCompressor(typeTraits, 0.001f, 2);
     }
 
@@ -108,19 +106,18 @@
         }
     }
 
-    // assumptions:
-    // 1. prefix tuple are stored contiguously
-    // 2. prefix tuple are located before tuples (physically on the page)
-    // 3. prefix tuple are sorted (last prefix tuple is at highest offset)
-    // this procedure will not move prefix tuples
+    // Assumptions:
+    // 1) prefix tuples are stored contiguously
+    // 2) prefix tuples are located before tuples (physically on the page)
+    // 3) prefix tuples are sorted (last prefix tuple is at highest offset)
+    // This procedure will not move prefix tuples.
     @Override
     public boolean compact() {
         resetSpaceParams();
 
         int tupleCount = buf.getInt(tupleCountOff);
 
-        // determine start of target free space (depends on assumptions stated
-        // above)
+        // determine start of target free space (depends on assumptions stated above)
         int freeSpace = buf.getInt(freeSpaceOff);
         int prefixTupleCount = buf.getInt(prefixTupleCountOff);
         if (prefixTupleCount > 0) {
@@ -185,8 +182,7 @@
         int length = tupleSlotOff - slotEndOff;
         System.arraycopy(buf.array(), slotEndOff, buf.array(), slotEndOff + slotManager.getSlotSize(), length);
 
-        // maintain space information, get size of tuple suffix (suffix
-        // could be entire tuple)
+        // maintain space information, get size of tuple suffix (suffix could be entire tuple)
         int tupleSize = 0;
         int suffixFieldStart = 0;
         if (prefixSlotNum == FieldPrefixSlotManager.TUPLE_UNCOMPRESSED) {
@@ -317,7 +313,8 @@
             bytesWritten = tupleWriter.writeTupleFields(newTuple, numPrefixFields, fieldCount - numPrefixFields,
                     buf.array(), suffixTupleStartOff);
         } else {
-            // Insert the new tuple suffix at the end of the free space, and change the slot value (effectively "deleting" the old tuple).
+            // Insert the new tuple suffix at the end of the free space, and change 
+            // the slot value (effectively "deleting" the old tuple).
             int newSuffixTupleStartOff = buf.getInt(freeSpaceOff);
             bytesWritten = tupleWriter.writeTupleFields(newTuple, numPrefixFields, fieldCount - numPrefixFields,
                     buf.array(), newSuffixTupleStartOff);
@@ -380,13 +377,13 @@
     }
 
     @Override
-    public ITupleReference getBeforeTuple(ITupleReference tuple, int targetTupleIndex) throws TreeIndexException {
+    public ITupleReference getMatchingKeyTuple(ITupleReference searchTuple, int targetTupleIndex) {
         int tupleIndex = slotManager.decodeSecondSlotField(targetTupleIndex);
         // Examine the tuple index to determine whether it is valid or not.
         if (tupleIndex != slotManager.getGreatestKeyIndicator()) {
             // We need to check the key to determine whether it's an insert or an update.
             frameTuple.resetByTupleIndex(this, tupleIndex);
-            if (cmp.compare(tuple, frameTuple) == 0) {
+            if (cmp.compare(searchTuple, frameTuple) == 0) {
                 // The keys match, it's an update.
                 return frameTuple;
             }
@@ -440,7 +437,7 @@
         return buf.getInt(tupleCountOff);
     }
 
-    public ISlotManager getSlotManager() {
+    public IPrefixSlotManager getSlotManager() {
         return slotManager;
     }
 
@@ -577,8 +574,7 @@
             }
         }
 
-        // if we are splitting in the middle of a prefix both pages need to have
-        // the prefix slot and tuple
+        // if we are splitting in the middle of a prefix both pages need to have the prefix slot and tuple
         int boundaryTupleSlotOff = rf.slotManager.getTupleSlotOff(tuplesToLeft - 1);
         int boundaryTupleSlot = buf.getInt(boundaryTupleSlotOff);
         int boundaryPrefixSlotNum = rf.slotManager.decodeFirstSlotField(boundaryTupleSlot);
@@ -588,8 +584,7 @@
             prefixesToLeft++; // tuples on both pages share one prefix
         }
 
-        // move prefix tuples on right page to beginning of page and adjust
-        // prefix slots
+        // move prefix tuples on right page to beginning of page and adjust prefix slots
         if (prefixesToRight > 0 && prefixesToLeft > 0 && prefixTupleCount > 1) {
 
             int freeSpace = rf.getOrigFreeSpaceOff();
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrameFactory.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrameFactory.java
index 5defb27..79d2f3a 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrameFactory.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrameFactory.java
@@ -22,8 +22,9 @@
 public class BTreeFieldPrefixNSMLeafFrameFactory implements ITreeIndexFrameFactory {
 
     private static final long serialVersionUID = 1L;
+
     private final ITreeIndexTupleWriterFactory tupleWriterFactory;
-    
+
     public BTreeFieldPrefixNSMLeafFrameFactory(ITreeIndexTupleWriterFactory tupleWriterFactory) {
         this.tupleWriterFactory = tupleWriterFactory;
     }
@@ -35,6 +36,6 @@
 
     @Override
     public ITreeIndexTupleWriterFactory getTupleWriterFactory() {
-       return tupleWriterFactory;
+        return tupleWriterFactory;
     }
 }
\ No newline at end of file
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeLeafFrameType.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeLeafFrameType.java
index 6ff44be..bd543f8 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeLeafFrameType.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeLeafFrameType.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.hyracks.storage.am.btree.frames;
 
 public enum BTreeLeafFrameType {
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java
index 7208da6..d100772 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java
@@ -41,6 +41,7 @@
     private static final int childPtrSize = 4;
 
     private final ITreeIndexTupleReference cmpFrameTuple;
+
     private MultiComparator cmp;
 
     public BTreeNSMInteriorFrame(ITreeIndexTupleWriter tupleWriter) {
@@ -89,12 +90,9 @@
             System.arraycopy(tuple.getFieldData(tuple.getFieldCount() - 1), getLeftChildPageOff(tuple) + childPtrSize,
                     buf.array(), rightLeafOff, childPtrSize);
         } else {
-            // If slotOff has a right (slot-)neighbor then update its child
-            // pointer.
-            // The only time when this is NOT the case, is when this is the
-            // very first tuple (or when the splitkey goes into the rightmost
-            // slot but that
-            // case is handled in the if above).
+            // If slotOff has a right (slot-)neighbor then update its child pointer.
+            // The only time when this is NOT the case, is when this is the very first tuple 
+            // (or when the splitkey goes into the rightmost slot but that case is handled in the if above).
             if (buf.getInt(tupleCountOff) > 1) {
                 int rightNeighborOff = slotOff - slotManager.getSlotSize();
                 frameTuple.resetByTupleOffset(buf, slotManager.getTupleOff(rightNeighborOff));
@@ -159,11 +157,6 @@
     }
 
     @Override
-    public int findUpdateTupleIndex(ITupleReference tuple) throws TreeIndexException {
-        throw new UnsupportedOperationException("Cannot update tuples in interior node.");
-    }
-
-    @Override
     public void insertSorted(ITupleReference tuple) {
         int freeSpace = buf.getInt(freeSpaceOff);
         slotManager.insertSlot(slotManager.getGreatestKeyIndicator(), freeSpace);
@@ -256,8 +249,7 @@
             sortedTupleOffs.add(new SlotOffTupleOff(i, slotOff, tupleOff));
         }
         Collections.sort(sortedTupleOffs);
-        // Iterate over the sorted slots, and move their corresponding tuples to
-        // the left, reclaiming free space.
+        // Iterate over the sorted slots, and move their corresponding tuples to the left, reclaiming free space.
         for (int i = 0; i < sortedTupleOffs.size(); i++) {
             int tupleOff = sortedTupleOffs.get(i).tupleOff;
             frameTuple.resetByTupleOffset(buf, tupleOff);
@@ -280,8 +272,7 @@
         if (buf.getInt(tupleCountOff) == 0) {
             return buf.getInt(rightLeafOff);
         }
-        // Trivial cases where no low key or high key was given (e.g.
-        // during an index scan).
+        // Trivial cases where no low key or high key was given (e.g. during an index scan).
         ITupleReference tuple = null;
         FindTupleMode fsm = null;
         // The target comparator may be on a prefix of the BTree key fields.
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrameFactory.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrameFactory.java
index 8618df8..1491b55 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrameFactory.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrameFactory.java
@@ -22,6 +22,7 @@
 public class BTreeNSMInteriorFrameFactory implements ITreeIndexFrameFactory {
 
     private static final long serialVersionUID = 1L;
+
     private final ITreeIndexTupleWriterFactory tupleWriterFactory;
 
     public BTreeNSMInteriorFrameFactory(ITreeIndexTupleWriterFactory tupleWriterFactory) {
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMLeafFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMLeafFrame.java
index 6935ab0..7185629 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMLeafFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMLeafFrame.java
@@ -33,6 +33,7 @@
 
 public class BTreeNSMLeafFrame extends TreeIndexNSMFrame implements IBTreeLeafFrame {
     protected static final int nextLeafOff = smFlagOff + 1;
+
     private MultiComparator cmp;
 
     public BTreeNSMLeafFrame(ITreeIndexTupleWriter tupleWriter) {
@@ -86,12 +87,12 @@
     }
 
     @Override
-    public ITupleReference getBeforeTuple(ITupleReference tuple, int targetTupleIndex) throws TreeIndexException {
+    public ITupleReference getMatchingKeyTuple(ITupleReference searchTuple, int targetTupleIndex) {
         // Examine the tuple index to determine whether it is valid or not.
         if (targetTupleIndex != slotManager.getGreatestKeyIndicator()) {
             // We need to check the key to determine whether it's an insert or an update/delete
             frameTuple.resetByTupleIndex(this, targetTupleIndex);
-            if (cmp.compare(tuple, frameTuple) == 0) {
+            if (cmp.compare(searchTuple, frameTuple) == 0) {
                 // The keys match, it's an update/delete
                 return frameTuple;
             }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMLeafFrameFactory.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMLeafFrameFactory.java
index 9508df5..b445fa8 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMLeafFrameFactory.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMLeafFrameFactory.java
@@ -22,8 +22,9 @@
 public class BTreeNSMLeafFrameFactory implements ITreeIndexFrameFactory {
 
     private static final long serialVersionUID = 1L;
+
     private final ITreeIndexTupleWriterFactory tupleWriterFactory;
-    
+
     public BTreeNSMLeafFrameFactory(ITreeIndexTupleWriterFactory tupleWriterFactory) {
         this.tupleWriterFactory = tupleWriterFactory;
     }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/OrderedSlotManager.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/OrderedSlotManager.java
index 5f507f5..e51ee99 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/OrderedSlotManager.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/OrderedSlotManager.java
@@ -23,8 +23,8 @@
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
 
 public class OrderedSlotManager extends AbstractSlotManager {
-    
-	@Override
+
+    @Override
     public int findTupleIndex(ITupleReference searchKey, ITreeIndexTupleReference frameTuple, MultiComparator multiCmp,
             FindTupleMode mode, FindTupleNoExactMatchPolicy matchPolicy) {
         if (frame.getTupleCount() <= 0) {
@@ -34,12 +34,12 @@
         int mid;
         int begin = 0;
         int end = frame.getTupleCount() - 1;
-        
+
         while (begin <= end) {
             mid = (begin + end) / 2;
-            frameTuple.resetByTupleIndex(frame, mid);            
-            
-            int cmp = multiCmp.compare(searchKey, frameTuple);            
+            frameTuple.resetByTupleIndex(frame, mid);
+
+            int cmp = multiCmp.compare(searchKey, frameTuple);
             if (cmp < 0) {
                 end = mid - 1;
             } else if (cmp > 0) {
@@ -87,7 +87,7 @@
             }
         }
     }
-    
+
     @Override
     public int insertSlot(int tupleIndex, int tupleOff) {
         int slotOff = getSlotOff(tupleIndex);
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
index 3381597..6a12e55 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
@@ -61,7 +61,6 @@
     public static final float DEFAULT_FILL_FACTOR = 0.7f;
 
     private final static long RESTART_OP = Long.MIN_VALUE;
-
     private final static int MAX_RESTARTS = 10;
 
     private final ReadWriteLock treeLatch;
@@ -303,7 +302,7 @@
 
             // Perform an update (delete + insert) if the updateTupleIndex != -1
             if (updateTupleIndex != -1) {
-                ITupleReference beforeTuple = ctx.leafFrame.getBeforeTuple(tuple, updateTupleIndex);
+                ITupleReference beforeTuple = ctx.leafFrame.getMatchingKeyTuple(tuple, updateTupleIndex);
                 ctx.modificationCallback.found(beforeTuple);
                 ctx.leafFrame.delete(tuple, updateTupleIndex);
             } else {
@@ -319,10 +318,6 @@
             rightFrame.setNextLeaf(ctx.leafFrame.getNextLeaf());
             ctx.leafFrame.setNextLeaf(rightPageId);
 
-            // TODO: we just use increasing numbers as pageLsn,
-            // we
-            // should tie this together with the LogManager and
-            // TransactionManager
             rightFrame.setPageLsn(rightFrame.getPageLsn() + 1);
             ctx.leafFrame.setPageLsn(ctx.leafFrame.getPageLsn() + 1);
 
@@ -340,7 +335,7 @@
     private boolean updateLeaf(ITupleReference tuple, int oldTupleIndex, int pageId, BTreeOpContext ctx)
             throws Exception {
         FrameOpSpaceStatus spaceStatus = ctx.leafFrame.hasSpaceUpdate(tuple, oldTupleIndex);
-        ITupleReference beforeTuple = ctx.leafFrame.getBeforeTuple(tuple, oldTupleIndex);
+        ITupleReference beforeTuple = ctx.leafFrame.getMatchingKeyTuple(tuple, oldTupleIndex);
         boolean restartOp = false;
         switch (spaceStatus) {
             case SUFFICIENT_INPLACE_SPACE: {
@@ -376,7 +371,7 @@
     private boolean upsertLeaf(ITupleReference tuple, int targetTupleIndex, int pageId, BTreeOpContext ctx)
             throws Exception {
         boolean restartOp = false;
-        ITupleReference beforeTuple = ctx.leafFrame.getBeforeTuple(tuple, targetTupleIndex);
+        ITupleReference beforeTuple = ctx.leafFrame.getMatchingKeyTuple(tuple, targetTupleIndex);
         if (ctx.acceptor.accept(beforeTuple)) {
             if (beforeTuple == null) {
                 restartOp = insertLeaf(tuple, targetTupleIndex, pageId, ctx);
@@ -411,9 +406,6 @@
                     ctx.smPages.add(rightPageId);
                     ctx.interiorFrame.setSmFlag(true);
                     rightFrame.setSmFlag(true);
-                    // TODO: we just use increasing numbers as pageLsn, we
-                    // should tie this together with the LogManager and
-                    // TransactionManager
                     rightFrame.setPageLsn(rightFrame.getPageLsn() + 1);
                     ctx.interiorFrame.setPageLsn(ctx.interiorFrame.getPageLsn() + 1);
 
@@ -452,7 +444,7 @@
             throw new BTreeNonExistentKeyException("Trying to delete a tuple with a nonexistent key in leaf node.");
         }
         int tupleIndex = ctx.leafFrame.findDeleteTupleIndex(tuple);
-        ITupleReference beforeTuple = ctx.leafFrame.getBeforeTuple(tuple, tupleIndex);
+        ITupleReference beforeTuple = ctx.leafFrame.getMatchingKeyTuple(tuple, tupleIndex);
         ctx.modificationCallback.found(beforeTuple);
         ctx.leafFrame.delete(tuple, tupleIndex);
         return false;
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeCursorInitialState.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeCursorInitialState.java
index 9367204..60cd455 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeCursorInitialState.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeCursorInitialState.java
@@ -7,13 +7,10 @@
 
 public class BTreeCursorInitialState implements ICursorInitialState {
 
-    private ICachedPage page;
-    
     // This is only used by the LSM-RTree
     private int pageId;
-
+    private ICachedPage page;
     private ISearchOperationCallback searchCallback;
-    
     private MultiComparator originalKeyCmp;
 
     public BTreeCursorInitialState(ICachedPage page, ISearchOperationCallback searchCallback) {
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeOpContext.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeOpContext.java
index c5f6bd6..cf5361a 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeOpContext.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeOpContext.java
@@ -32,6 +32,7 @@
 
 public class BTreeOpContext implements IIndexOpContext {
     private final int INIT_ARRAYLIST_SIZE = 6;
+
     public MultiComparator cmp;
     public ITreeIndexFrameFactory leafFrameFactory;
     public ITreeIndexFrameFactory interiorFrameFactory;
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeSplitKey.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeSplitKey.java
index e664e5b..2606c08 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeSplitKey.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTreeSplitKey.java
@@ -21,15 +21,16 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleReference;
 
 public class BTreeSplitKey implements ISplitKey {
+    public final ITreeIndexTupleReference tuple;
+
     public byte[] data = null;
     public ByteBuffer buf = null;
-    public ITreeIndexTupleReference tuple;
     public int keySize = 0;
 
     public BTreeSplitKey(ITreeIndexTupleReference tuple) {
         this.tuple = tuple;
     }
-    
+
     public void initData(int keySize) {
         // try to reuse existing memory from a lower-level split if possible
         this.keySize = keySize;
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixPrefixTupleReference.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixPrefixTupleReference.java
index 80ac173..44fcdef 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixPrefixTupleReference.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixPrefixTupleReference.java
@@ -16,6 +16,7 @@
 package edu.uci.ics.hyracks.storage.am.btree.impls;
 
 import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
+import edu.uci.ics.hyracks.storage.am.btree.api.IPrefixSlotManager;
 import edu.uci.ics.hyracks.storage.am.btree.frames.BTreeFieldPrefixNSMLeafFrame;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrame;
 import edu.uci.ics.hyracks.storage.am.common.tuples.TypeAwareTupleReference;
@@ -30,10 +31,11 @@
     @Override
     public void resetByTupleIndex(ITreeIndexFrame frame, int tupleIndex) {
         BTreeFieldPrefixNSMLeafFrame concreteFrame = (BTreeFieldPrefixNSMLeafFrame) frame;
-        int prefixSlotOff = concreteFrame.slotManager.getPrefixSlotOff(tupleIndex);
+        IPrefixSlotManager slotManager = concreteFrame.getSlotManager();
+        int prefixSlotOff = slotManager.getPrefixSlotOff(tupleIndex);
         int prefixSlot = concreteFrame.getBuffer().getInt(prefixSlotOff);
-        setFieldCount(concreteFrame.slotManager.decodeFirstSlotField(prefixSlot));
-        tupleStartOff = concreteFrame.slotManager.decodeSecondSlotField(prefixSlot);
+        setFieldCount(slotManager.decodeFirstSlotField(prefixSlot));
+        tupleStartOff = slotManager.decodeSecondSlotField(prefixSlot);
         buf = concreteFrame.getBuffer();
         resetByTupleOffset(buf, tupleStartOff);
     }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixSlotManager.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixSlotManager.java
index 6525bb9..4c66fbb 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixSlotManager.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixSlotManager.java
@@ -28,16 +28,17 @@
 
 public class FieldPrefixSlotManager implements IPrefixSlotManager {
 
-    private static final int slotSize = 4;
     public static final int TUPLE_UNCOMPRESSED = 0xFF;
     public static final int MAX_PREFIX_SLOTS = 0xFE;
     public static final int GREATEST_KEY_INDICATOR = 0x00FFFFFF;
     public static final int ERROR_INDICATOR = 0x00FFFFFE;
 
+    private static final int slotSize = 4;
+
     private ByteBuffer buf;
     private BTreeFieldPrefixNSMLeafFrame frame;
     private MultiComparator cmp;
-    
+
     public int decodeFirstSlotField(int slot) {
         return (slot & 0xFF000000) >>> 24;
     }
@@ -117,23 +118,17 @@
             }
         }
 
-        // System.out.println("SLOTLBOUND: " + tuplePrefixSlotNumLbound);
-        // System.out.println("SLOTUBOUND: " + tuplePrefixSlotNumUbound);
-
         int tupleMid = -1;
         int tupleBegin = 0;
         int tupleEnd = frame.getTupleCount() - 1;
 
-        // binary search on tuples, guided by the lower and upper bounds on
-        // prefixSlotNum
+        // binary search on tuples, guided by the lower and upper bounds on prefixSlotNum
         while (tupleBegin <= tupleEnd) {
             tupleMid = (tupleBegin + tupleEnd) / 2;
             int tupleSlotOff = getTupleSlotOff(tupleMid);
             int tupleSlot = buf.getInt(tupleSlotOff);
             int prefixSlotNum = decodeFirstSlotField(tupleSlot);
 
-            // System.out.println("RECS: " + recBegin + " " + recMid + " " +
-            // recEnd);
             int cmp = 0;
             if (prefixSlotNum == TUPLE_UNCOMPRESSED) {
                 frameTuple.resetByTupleIndex(frame, tupleMid);
@@ -160,18 +155,15 @@
                     else
                         tupleEnd = tupleMid - 1;
                 } else {
-                	if (mode == FindTupleMode.EXCLUSIVE_ERROR_IF_EXISTS) {
-                		return encodeSlotFields(prefixMatch, ERROR_INDICATOR);
-                	} else {
-                		return encodeSlotFields(prefixMatch, tupleMid);
-                	}
+                    if (mode == FindTupleMode.EXCLUSIVE_ERROR_IF_EXISTS) {
+                        return encodeSlotFields(prefixMatch, ERROR_INDICATOR);
+                    } else {
+                        return encodeSlotFields(prefixMatch, tupleMid);
+                    }
                 }
             }
         }
 
-        // System.out.println("RECS: " + recBegin + " " + recMid + " " +
-        // recEnd);
-
         if (mode == FindTupleMode.EXACT)
             return encodeSlotFields(prefixMatch, ERROR_INDICATOR);
 
@@ -223,7 +215,7 @@
     public int insertSlot(int slot, int tupleOff) {
         int slotNum = decodeSecondSlotField(slot);
         if (slotNum == ERROR_INDICATOR) {
-        	System.out.println("WOW BIG PROBLEM!");
+            System.out.println("WOW BIG PROBLEM!");
         }
         if (slotNum == GREATEST_KEY_INDICATOR) {
             int slotOff = getTupleSlotEndOff() - slotSize;
@@ -255,50 +247,49 @@
         buf.putInt(getPrefixSlotOff(tupleIndex), slot);
     }
 
-	@Override
-	public int getGreatestKeyIndicator() {
-		return GREATEST_KEY_INDICATOR;
-	}
+    @Override
+    public int getGreatestKeyIndicator() {
+        return GREATEST_KEY_INDICATOR;
+    }
 
-	@Override
-	public int getErrorIndicator() {
-		return ERROR_INDICATOR;
-	}
+    @Override
+    public int getErrorIndicator() {
+        return ERROR_INDICATOR;
+    }
 
-	@Override
-	public void setFrame(ITreeIndexFrame frame) {
-		this.frame = (BTreeFieldPrefixNSMLeafFrame)frame;
+    @Override
+    public void setFrame(ITreeIndexFrame frame) {
+        this.frame = (BTreeFieldPrefixNSMLeafFrame) frame;
         this.buf = frame.getBuffer();
-	}
+    }
 
-	@Override
-	public int findTupleIndex(ITupleReference searchKey,
-			ITreeIndexTupleReference frameTuple, MultiComparator multiCmp,
-			FindTupleMode mode, FindTupleNoExactMatchPolicy matchPolicy) {
-		throw new UnsupportedOperationException("Not implemented.");
-	}
-	
-	@Override
-	public int getSlotStartOff() {
-		throw new UnsupportedOperationException("Not implemented.");
-	}
+    @Override
+    public int findTupleIndex(ITupleReference searchKey, ITreeIndexTupleReference frameTuple, MultiComparator multiCmp,
+            FindTupleMode mode, FindTupleNoExactMatchPolicy matchPolicy) {
+        throw new UnsupportedOperationException("Not implemented.");
+    }
 
-	@Override
-	public int getSlotEndOff() {
-		throw new UnsupportedOperationException("Not implemented.");
-	}
+    @Override
+    public int getSlotStartOff() {
+        throw new UnsupportedOperationException("Not implemented.");
+    }
 
-	@Override
-	public int getTupleOff(int slotOff) {
-		throw new UnsupportedOperationException("Not implemented.");
-	}
+    @Override
+    public int getSlotEndOff() {
+        throw new UnsupportedOperationException("Not implemented.");
+    }
 
-	@Override
-	public int getSlotOff(int tupleIndex) {
-		throw new UnsupportedOperationException("Not implemented.");
-	}
-	
-	public void setMultiComparator(MultiComparator cmp) {
-		this.cmp = cmp;
-	}
+    @Override
+    public int getTupleOff(int slotOff) {
+        throw new UnsupportedOperationException("Not implemented.");
+    }
+
+    @Override
+    public int getSlotOff(int tupleIndex) {
+        throw new UnsupportedOperationException("Not implemented.");
+    }
+
+    public void setMultiComparator(MultiComparator cmp) {
+        this.cmp = cmp;
+    }
 }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixTupleReference.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixTupleReference.java
index 9644a3e..b7174d4 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixTupleReference.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixTupleReference.java
@@ -2,18 +2,20 @@
 
 import java.nio.ByteBuffer;
 
+import edu.uci.ics.hyracks.storage.am.btree.api.IPrefixSlotManager;
 import edu.uci.ics.hyracks.storage.am.btree.frames.BTreeFieldPrefixNSMLeafFrame;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrame;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleReference;
 
 public class FieldPrefixTupleReference implements ITreeIndexTupleReference {
 
+    private final ITreeIndexTupleReference helperTuple;
+
     private BTreeFieldPrefixNSMLeafFrame frame;
     private int prefixTupleStartOff;
     private int suffixTupleStartOff;
     private int numPrefixFields;
     private int fieldCount;
-    private ITreeIndexTupleReference helperTuple;
 
     public FieldPrefixTupleReference(ITreeIndexTupleReference helperTuple) {
         this.helperTuple = helperTuple;
@@ -23,17 +25,17 @@
     @Override
     public void resetByTupleIndex(ITreeIndexFrame frame, int tupleIndex) {
         this.frame = (BTreeFieldPrefixNSMLeafFrame) frame;
-
-        int tupleSlotOff = this.frame.slotManager.getTupleSlotOff(tupleIndex);
+        IPrefixSlotManager slotManager = this.frame.getSlotManager();
+        int tupleSlotOff = slotManager.getTupleSlotOff(tupleIndex);
         int tupleSlot = this.frame.getBuffer().getInt(tupleSlotOff);
-        int prefixSlotNum = this.frame.slotManager.decodeFirstSlotField(tupleSlot);
-        suffixTupleStartOff = this.frame.slotManager.decodeSecondSlotField(tupleSlot);
+        int prefixSlotNum = slotManager.decodeFirstSlotField(tupleSlot);
+        suffixTupleStartOff = slotManager.decodeSecondSlotField(tupleSlot);
 
         if (prefixSlotNum != FieldPrefixSlotManager.TUPLE_UNCOMPRESSED) {
-            int prefixSlotOff = this.frame.slotManager.getPrefixSlotOff(prefixSlotNum);
+            int prefixSlotOff = slotManager.getPrefixSlotOff(prefixSlotNum);
             int prefixSlot = this.frame.getBuffer().getInt(prefixSlotOff);
-            numPrefixFields = this.frame.slotManager.decodeFirstSlotField(prefixSlot);
-            prefixTupleStartOff = this.frame.slotManager.decodeSecondSlotField(prefixSlot);
+            numPrefixFields = slotManager.decodeFirstSlotField(prefixSlot);
+            prefixTupleStartOff = slotManager.decodeSecondSlotField(prefixSlot);
         } else {
             numPrefixFields = 0;
             prefixTupleStartOff = -1;
@@ -96,20 +98,21 @@
     public int getTupleSize() {
         return getSuffixTupleSize() + getPrefixTupleSize();
     }
-    
+
     public int getSuffixTupleSize() {
         helperTuple.setFieldCount(numPrefixFields, fieldCount - numPrefixFields);
         helperTuple.resetByTupleOffset(frame.getBuffer(), suffixTupleStartOff);
         return helperTuple.getTupleSize();
     }
-    
+
     public int getPrefixTupleSize() {
-        if (numPrefixFields == 0) return 0;
+        if (numPrefixFields == 0)
+            return 0;
         helperTuple.setFieldCount(numPrefixFields);
         helperTuple.resetByTupleOffset(frame.getBuffer(), prefixTupleStartOff);
         return helperTuple.getTupleSize();
     }
-    
+
     public int getNumPrefixFields() {
         return numPrefixFields;
     }
diff --git a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ISlotManager.java b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ISlotManager.java
index 2619493..3e5e018 100644
--- a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ISlotManager.java
+++ b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ISlotManager.java
@@ -21,27 +21,26 @@
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
 
 public interface ISlotManager {
-	public int findTupleIndex(ITupleReference searchKey,
-			ITreeIndexTupleReference frameTuple, MultiComparator multiCmp,
-			FindTupleMode mode, FindTupleNoExactMatchPolicy matchPolicy);
+    public int findTupleIndex(ITupleReference searchKey, ITreeIndexTupleReference frameTuple, MultiComparator multiCmp,
+            FindTupleMode mode, FindTupleNoExactMatchPolicy matchPolicy);
 
-	public int getGreatestKeyIndicator();
-	
-	public int getErrorIndicator();
+    public int getGreatestKeyIndicator();
 
-	public void setFrame(ITreeIndexFrame frame);
-	
-	public int insertSlot(int tupleIndex, int tupleOff);
+    public int getErrorIndicator();
 
-	public int getSlotStartOff();
+    public void setFrame(ITreeIndexFrame frame);
 
-	public int getSlotEndOff();
+    public int getTupleOff(int slotOff);
 
-	public int getTupleOff(int slotOff);
+    public int insertSlot(int tupleIndex, int tupleOff);
 
-	public void setSlot(int slotOff, int value);
+    public int getSlotStartOff();
 
-	public int getSlotOff(int tupleIndex);
+    public int getSlotEndOff();
 
-	public int getSlotSize();
+    public int getSlotOff(int tupleIndex);
+
+    public int getSlotSize();
+
+    public void setSlot(int slotOff, int value);
 }
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeBulkLoadTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeBulkLoadTest.java
index cb76cc8..5417ca1 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeBulkLoadTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeBulkLoadTest.java
@@ -26,15 +26,14 @@
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestContext;
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestHarness;
 
-@SuppressWarnings("rawtypes")
 public class BTreeBulkLoadTest extends OrderedIndexBulkLoadTest {
 
+    private final BTreeTestHarness harness = new BTreeTestHarness();
+
     public BTreeBulkLoadTest() {
         super(BTreeTestHarness.LEAF_FRAMES_TO_TEST, 1);
     }
 
-    private final BTreeTestHarness harness = new BTreeTestHarness();
-
     @Before
     public void setUp() throws HyracksDataException {
         harness.setUp();
@@ -45,6 +44,7 @@
         harness.tearDown();
     }
 
+    @SuppressWarnings("rawtypes")
     @Override
     protected OrderedIndexTestContext createTestContext(ISerializerDeserializer[] fieldSerdes, int numKeys,
             BTreeLeafFrameType leafType) throws Exception {
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeDeleteTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeDeleteTest.java
index 596b136..10cd59f 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeDeleteTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeDeleteTest.java
@@ -26,15 +26,14 @@
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestContext;
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestHarness;
 
-@SuppressWarnings("rawtypes")
 public class BTreeDeleteTest extends OrderedIndexDeleteTest {
 
+    private final BTreeTestHarness harness = new BTreeTestHarness();
+
     public BTreeDeleteTest() {
         super(BTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
 
-    private final BTreeTestHarness harness = new BTreeTestHarness();
-
     @Before
     public void setUp() throws HyracksDataException {
         harness.setUp();
@@ -45,6 +44,7 @@
         harness.tearDown();
     }
 
+    @SuppressWarnings("rawtypes")
     @Override
     protected OrderedIndexTestContext createTestContext(ISerializerDeserializer[] fieldSerdes, int numKeys,
             BTreeLeafFrameType leafType) throws Exception {
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeInsertTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeInsertTest.java
index 14ae6f7..efe7579 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeInsertTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeInsertTest.java
@@ -27,22 +27,22 @@
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestHarness;
 
 /**
- * Tests the BTree insert operation with strings and integer fields using
- * various numbers of key and payload fields.
- * Each tests first fills a BTree with randomly generated tuples. We compare the
- * following operations against expected results: 1. Point searches for all
- * tuples. 2. Ordered scan. 3. Disk-order scan. 4. Range search (and prefix
- * search for composite keys).
+ * Tests the BTree insert operation with strings and integer fields using 
+ * various numbers of key and payload fields. Each tests first fills a BTree with 
+ * randomly generated tuples. We compare the following operations against expected results: 
+ *      1) Point searches for all tuples 
+ *      2) Ordered scan
+ *      3) Disk-order scan
+ *      4) Range search (and prefix search for composite keys)
  */
-@SuppressWarnings("rawtypes")
 public class BTreeInsertTest extends OrderedIndexInsertTest {
 
+    private final BTreeTestHarness harness = new BTreeTestHarness();
+
     public BTreeInsertTest() {
         super(BTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
 
-    private final BTreeTestHarness harness = new BTreeTestHarness();
-
     @Before
     public void setUp() throws HyracksDataException {
         harness.setUp();
@@ -53,6 +53,7 @@
         harness.tearDown();
     }
 
+    @SuppressWarnings("rawtypes")
     @Override
     protected OrderedIndexTestContext createTestContext(ISerializerDeserializer[] fieldSerdes, int numKeys,
             BTreeLeafFrameType leafType) throws Exception {
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeLifecycleTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeLifecycleTest.java
index fa2de99..10e2da1 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeLifecycleTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeLifecycleTest.java
@@ -17,10 +17,12 @@
 public class BTreeLifecycleTest extends AbstractIndexLifecycleTest {
     private final BTreeTestHarness harness = new BTreeTestHarness();
 
+    @SuppressWarnings("rawtypes")
     private final ISerializerDeserializer[] fieldSerdes = new ISerializerDeserializer[] { IntegerSerializerDeserializer.INSTANCE };
 
     private ITreeIndexFrame frame = null;
 
+    @SuppressWarnings("rawtypes")
     private ITreeIndexTestContext<? extends CheckTuple> testCtx;
 
     @Override
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeSearchCursorTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeSearchCursorTest.java
index d09a240..ad0b21e 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeSearchCursorTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeSearchCursorTest.java
@@ -53,7 +53,6 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexAccessor;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexCursor;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrameFactory;
-import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexMetaDataFrame;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexMetaDataFrameFactory;
 import edu.uci.ics.hyracks.storage.am.common.frames.LIFOMetaDataFrameFactory;
 import edu.uci.ics.hyracks.storage.am.common.freepage.LinkedListFreePageManager;
@@ -62,15 +61,11 @@
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 
 public class BTreeSearchCursorTest extends AbstractBTreeTest {
-    // Declare fields
-    int fieldCount = 2;
-    ITypeTraits[] typeTraits = new ITypeTraits[fieldCount];
-
-    TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
-    ITreeIndexMetaDataFrameFactory metaFrameFactory = new LIFOMetaDataFrameFactory();
-    ITreeIndexMetaDataFrame metaFrame = metaFrameFactory.createFrame();
-
-    Random rnd = new Random(50);
+    private final int fieldCount = 2;
+    private final ITypeTraits[] typeTraits = new ITypeTraits[fieldCount];
+    private final TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
+    private final ITreeIndexMetaDataFrameFactory metaFrameFactory = new LIFOMetaDataFrameFactory();
+    private final Random rnd = new Random(50);
 
     @Before
     public void setUp() throws HyracksDataException {
@@ -138,8 +133,6 @@
             }
         }
 
-        // btree.printTree(leafFrame, interiorFrame, recDescSers);
-
         int minSearchKey = -100;
         int maxSearchKey = 100;
 
@@ -214,8 +207,6 @@
             }
         }
 
-        // btree.printTree(leafFrame, interiorFrame, recDescSers);
-
         int minSearchKey = -100;
         int maxSearchKey = 100;
 
@@ -290,8 +281,6 @@
             }
         }
 
-        // btree.printTree(leafFrame, interiorFrame, recDescSers);
-
         int minSearchKey = -100;
         int maxSearchKey = 100;
 
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeStatsTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeStatsTest.java
index 36aa21b..57535b2 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeStatsTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeStatsTest.java
@@ -50,7 +50,8 @@
     private static final int NUM_PAGES = 1000;
     private static final int MAX_OPEN_FILES = 10;
     private static final int HYRACKS_FRAME_SIZE = 128;
-    private IHyracksTaskContext ctx = TestUtils.create(HYRACKS_FRAME_SIZE);
+
+    private final IHyracksTaskContext ctx = TestUtils.create(HYRACKS_FRAME_SIZE);
 
     @Test
     public void test01() throws Exception {
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateSearchTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateSearchTest.java
index 4bc10b8..f01799d 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateSearchTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateSearchTest.java
@@ -34,7 +34,6 @@
 import edu.uci.ics.hyracks.storage.am.common.tuples.TypeAwareTupleWriterFactory;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 
-@SuppressWarnings("rawtypes")
 public class BTreeUpdateSearchTest extends AbstractBTreeTest {
 
     // Update scan test on fixed-length tuples.
@@ -53,6 +52,7 @@
         IBinaryComparatorFactory[] cmpFactories = new IBinaryComparatorFactory[keyFieldCount];
         cmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
 
+        @SuppressWarnings("rawtypes")
         ISerializerDeserializer[] recDescSers = { IntegerSerializerDeserializer.INSTANCE,
                 IntegerSerializerDeserializer.INSTANCE };
 
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateTest.java
index 5461cbd..89bb50e5 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateTest.java
@@ -26,15 +26,14 @@
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestContext;
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestHarness;
 
-@SuppressWarnings("rawtypes")
 public class BTreeUpdateTest extends OrderedIndexUpdateTest {
 
+    private final BTreeTestHarness harness = new BTreeTestHarness();
+
     public BTreeUpdateTest() {
         super(BTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
 
-    private final BTreeTestHarness harness = new BTreeTestHarness();
-
     @Before
     public void setUp() throws HyracksDataException {
         harness.setUp();
@@ -45,6 +44,7 @@
         harness.tearDown();
     }
 
+    @SuppressWarnings("rawtypes")
     @Override
     protected OrderedIndexTestContext createTestContext(ISerializerDeserializer[] fieldSerdes, int numKeys,
             BTreeLeafFrameType leafType) throws Exception {
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpsertTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpsertTest.java
index 4141832..ab32156 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpsertTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpsertTest.java
@@ -27,14 +27,14 @@
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestHarness;
 
 /**
- * Tests the BTree insert operation with strings and integer fields using
- * various numbers of key and payload fields.
- * Each tests first fills a BTree with randomly generated tuples. We compare the
- * following operations against expected results: 1. Point searches for all
- * tuples. 2. Ordered scan. 3. Disk-order scan. 4. Range search (and prefix
- * search for composite keys).
+ * Tests the BTree insert operation with strings and integer fields using 
+ * various numbers of key and payload fields. Each tests first fills a BTree with 
+ * randomly generated tuples. We compare the following operations against expected results: 
+ *      1) Point searches for all tuples 
+ *      2) Ordered scan
+ *      3) Disk-order scan
+ *      4) Range search (and prefix search for composite keys)
  */
-@SuppressWarnings("rawtypes")
 public class BTreeUpsertTest extends OrderedIndexUpsertTest {
 
     public BTreeUpsertTest() {
@@ -53,6 +53,7 @@
         harness.tearDown();
     }
 
+    @SuppressWarnings("rawtypes")
     @Override
     protected OrderedIndexTestContext createTestContext(ISerializerDeserializer[] fieldSerdes, int numKeys,
             BTreeLeafFrameType leafType) throws Exception {
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/FieldPrefixNSMTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/FieldPrefixNSMTest.java
index 9f7daf5..1bf511e 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/FieldPrefixNSMTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/FieldPrefixNSMTest.java
@@ -50,10 +50,9 @@
 import edu.uci.ics.hyracks.storage.common.file.BufferedFileHandle;
 import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
-@SuppressWarnings("rawtypes")
 public class FieldPrefixNSMTest extends AbstractBTreeTest {
 
-    private static final int PAGE_SIZE = 32768; // 32K
+    private static final int PAGE_SIZE = 32768;
     private static final int NUM_PAGES = 40;
     private static final int MAX_OPEN_FILES = 10;
     private static final int HYRACKS_FRAME_SIZE = 128;
@@ -75,6 +74,7 @@
         ArrayTupleBuilder tb = new ArrayTupleBuilder(3);
         DataOutput dos = tb.getDataOutput();
 
+        @SuppressWarnings("rawtypes")
         ISerializerDeserializer[] recDescSers = { IntegerSerializerDeserializer.INSTANCE,
                 IntegerSerializerDeserializer.INSTANCE, IntegerSerializerDeserializer.INSTANCE };
         RecordDescriptor recDesc = new RecordDescriptor(recDescSers);
@@ -117,6 +117,7 @@
         MultiComparator cmp = new MultiComparator(cmps);
 
         // just for printing
+        @SuppressWarnings("rawtypes")
         ISerializerDeserializer[] fieldSerdes = { IntegerSerializerDeserializer.INSTANCE,
                 IntegerSerializerDeserializer.INSTANCE, IntegerSerializerDeserializer.INSTANCE };
 
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/multithread/BTreeMultiThreadTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/multithread/BTreeMultiThreadTest.java
index e42abdf..bc71052 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/multithread/BTreeMultiThreadTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/multithread/BTreeMultiThreadTest.java
@@ -33,9 +33,8 @@
 
 public class BTreeMultiThreadTest extends OrderedIndexMultiThreadTest {
 
-    private BTreeTestHarness harness = new BTreeTestHarness();
-
-    private BTreeTestWorkerFactory workerFactory = new BTreeTestWorkerFactory();
+    private final BTreeTestHarness harness = new BTreeTestHarness();
+    private final BTreeTestWorkerFactory workerFactory = new BTreeTestWorkerFactory();
 
     @Override
     protected void setUp() throws HyracksDataException {
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/multithread/BTreeTestWorker.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/multithread/BTreeTestWorker.java
index 7d8de7d..9be5a75 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/multithread/BTreeTestWorker.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/multithread/BTreeTestWorker.java
@@ -34,27 +34,27 @@
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
 
 public class BTreeTestWorker extends AbstractTreeIndexTestWorker {
-    
+
     private final BTree btree;
     private final int numKeyFields;
     private final ArrayTupleBuilder deleteTb;
     private final ArrayTupleReference deleteTuple = new ArrayTupleReference();
-    
+
     public BTreeTestWorker(DataGenThread dataGen, TestOperationSelector opSelector, ITreeIndex index, int numBatches) {
         super(dataGen, opSelector, index, numBatches);
         btree = (BTree) index;
         numKeyFields = btree.getComparatorFactories().length;
         deleteTb = new ArrayTupleBuilder(numKeyFields);
     }
-    
+
     @Override
-    public void performOp(ITupleReference tuple, TestOperation op) throws HyracksDataException, TreeIndexException {        
+    public void performOp(ITupleReference tuple, TestOperation op) throws HyracksDataException, TreeIndexException {
         BTree.BTreeAccessor accessor = (BTree.BTreeAccessor) indexAccessor;
         ITreeIndexCursor searchCursor = accessor.createSearchCursor();
         ITreeIndexCursor diskOrderScanCursor = accessor.createDiskOrderScanCursor();
         MultiComparator cmp = accessor.getOpContext().cmp;
         RangePredicate rangePred = new RangePredicate(tuple, tuple, true, true, cmp, cmp);
-        
+
         switch (op) {
             case INSERT:
                 try {
@@ -63,7 +63,7 @@
                     // Ignore duplicate keys, since we get random tuples.
                 }
                 break;
-                
+
             case DELETE:
                 // Create a tuple reference with only key fields.
                 deleteTb.reset();
@@ -77,7 +77,7 @@
                     // Ignore non-existant keys, since we get random tuples.
                 }
                 break;
-                
+
             case UPDATE:
                 try {
                     accessor.update(tuple);
@@ -87,21 +87,21 @@
                     // Ignore not updateable exception due to numKeys == numFields.
                 }
                 break;
-                
+
             case UPSERT:
                 accessor.upsert(tuple);
                 // Upsert should not throw. If it does, there's 
                 // a bigger problem and the test should fail.
                 break;
-                
-            case POINT_SEARCH: 
+
+            case POINT_SEARCH:
                 searchCursor.reset();
                 rangePred.setLowKey(tuple, true);
                 rangePred.setHighKey(tuple, true);
                 accessor.search(searchCursor, rangePred);
                 consumeCursorTuples(searchCursor);
                 break;
-                
+
             case SCAN:
                 searchCursor.reset();
                 rangePred.setLowKey(null, true);
@@ -109,21 +109,21 @@
                 accessor.search(searchCursor, rangePred);
                 consumeCursorTuples(searchCursor);
                 break;
-                
+
             case DISKORDER_SCAN:
                 diskOrderScanCursor.reset();
                 accessor.diskOrderScan(diskOrderScanCursor);
                 consumeCursorTuples(diskOrderScanCursor);
-                break;                            
-            
+                break;
+
             default:
                 throw new HyracksDataException("Op " + op.toString() + " not supported.");
         }
     }
-    
+
     private void consumeCursorTuples(ITreeIndexCursor cursor) throws HyracksDataException {
         try {
-            while(cursor.hasNext()) {
+            while (cursor.hasNext()) {
                 cursor.next();
             }
         } finally {