o Bulkloader code cleanup
o Deleting the temprorary files when quiting the tests
diff --git a/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java b/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
index 49ce27e..16c63bd 100644
--- a/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
+++ b/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
@@ -130,41 +130,25 @@
 
 
     /**
-     * Bulk Load data into a persisted BTree
+     * Process the data, and creates files to store them sorted if necessary, or store them
+     * TODO readElements.
      *
-     * @param btree The persisted BTree in which we want to load the data
-     * @param iterator The iterator over the data to bulkload
-     * @param chunkSize The number of elements we may store in memory at each iteration
-     * @throws IOException If there is a problem while processing the data
+     * @param btree
+     * @param iterator
+     * @param sortedFiles
+     * @param tuples
+     * @param chunkSize
+     * @return
+     * @throws IOException
      */
-    public BTree<K, V> load( PersistedBTree<K, V> btree, Iterator<Tuple<K, V>> iterator, int chunkSize )
-        throws IOException
+    private int readElements( BTree<K, V> btree, Iterator<Tuple<K, V>> iterator, List<File> sortedFiles,
+        List<Tuple<K, V>> tuples, int chunkSize ) throws IOException
     {
-        if ( btree == null )
-        {
-            throw new RuntimeException( "Invalid BTree : it's null" );
-        }
-
-        if ( iterator == null )
-        {
-            // Nothing to do...
-            return null;
-        }
-
-        // Iterate through the elements by chunk
         int nbRead = 0;
         int nbIteration = 0;
-        boolean inMemory = true;
         int nbElems = 0;
+        boolean inMemory = true;
 
-        // An array of chukSize tuple max
-        List<Tuple<K, V>> tuples = new ArrayList<Tuple<K, V>>( chunkSize );
-
-        // The list of files we will use to store the sorted chunks
-        List<File> sortedFiles = new ArrayList<File>();
-
-        // Now, start to read all the tuples to sort them. We may use intermediate files
-        // for that purpose if we hit the threshold.
         while ( true )
         {
             nbIteration++;
@@ -184,7 +168,7 @@
                 {
                     // We have read all the data in one round trip, let's get out, no need
                     // to store the data on disk
-                    sortedFiles.add( flushToDisk( nbIteration, tuples, btree ) );
+                    ;
                 }
                 else
                 {
@@ -227,6 +211,56 @@
             }
         }
 
+        if ( !inMemory )
+        {
+            tuples.clear();
+        }
+
+        return nbElems;
+    }
+
+
+    /**
+     * Bulk Load data into a persisted BTree
+     *
+     * @param btree The persisted BTree in which we want to load the data
+     * @param iterator The iterator over the data to bulkload
+     * @param chunkSize The number of elements we may store in memory at each iteration
+     * @throws IOException If there is a problem while processing the data
+     */
+    public BTree<K, V> load( PersistedBTree<K, V> btree, Iterator<Tuple<K, V>> iterator, int chunkSize )
+        throws IOException
+    {
+        if ( btree == null )
+        {
+            throw new RuntimeException( "Invalid BTree : it's null" );
+        }
+
+        if ( iterator == null )
+        {
+            // Nothing to do...
+            return null;
+        }
+
+        // Iterate through the elements by chunk
+        boolean inMemory = true;
+
+        // The list of files we will use to store the sorted chunks
+        List<File> sortedFiles = new ArrayList<File>();
+
+        // An array of chukSize tuple max
+        List<Tuple<K, V>> tuples = new ArrayList<Tuple<K, V>>( chunkSize );
+
+        // Now, start to read all the tuples to sort them. We may use intermediate files
+        // for that purpose if we hit the threshold.
+        int nbElems = readElements( btree, iterator, sortedFiles, tuples, chunkSize );
+
+        // If the tuple list is empty, we have to process the load based on files, not in memory
+        if ( nbElems > 0 )
+        {
+            inMemory = tuples.size() > 0;
+        }
+
         // Now that we have processed all the data, we can start storing them in the btree
         Iterator<Tuple<K, Set<V>>> dataIterator = null;
         FileInputStream[] streams = null;
@@ -236,7 +270,6 @@
             // Here, we have all the data in memory, no need to merge files
             // We will build a simple iterator over the data
             dataIterator = createTupleIterator( btree, tuples );
-
         }
         else
         {
@@ -256,7 +289,7 @@
         // target btree.
         BTree<K, V> resultBTree = bulkLoad( btree, dataIterator, nbElems );
 
-        // Now, close the FileInputStream if we have some
+        // Now, close the FileInputStream, and delete them if we have some
         if ( !inMemory )
         {
             int nbFiles = sortedFiles.size();
@@ -264,6 +297,7 @@
             for ( int i = 0; i < nbFiles; i++ )
             {
                 streams[i].close();
+                sortedFiles.get( i ).delete();
             }
         }
 
@@ -775,19 +809,9 @@
 
         // Now, let's fill the levels
         LevelInfo leafLevel = levels.get( 0 );
-        int nbRead = 0;
 
         while ( dataIterator.hasNext() )
         {
-            nbRead++;
-            //System.out.println( "Adding #" + nbRead );
-            //System.out.println( "--------------------------------------------------------" );
-
-            //for ( int i = 0; i < leafLevel.currentPage.getNbElems(); i++ )
-            //{
-            //    System.out.println( "Key[" + i + "] = " + leafLevel.currentPage.getKey( i ) );
-            //}
-
             // let's fill page up to the point all the complete pages have been filled
             if ( leafLevel.nbAddedElems < leafLevel.nbElemsLimit )
             {
@@ -800,7 +824,6 @@
                 // The page is completed, update the parent's node and create a new current page
                 if ( leafLevel.currentPos == pageSize )
                 {
-                    //System.out.println( leafLevel.currentPage );
                     injectInNode( btree, leafLevel.currentPage, levels, 1 );
 
                     // The page is full, we have to create a new one
@@ -838,7 +861,6 @@
 
                     // Now inject the page into the node
                     injectInNode( btree, leafLevel.currentPage, levels, 1 );
-                    //System.out.println( leafLevel.currentPage );
 
                     // Create a new page for the remaining elements
                     nbToAdd = pageSize / 2;
@@ -859,7 +881,6 @@
                     injectInNode( btree, leafLevel.currentPage, levels, 1 );
 
                     // We are done
-                    //System.out.println( leafLevel.currentPage );
                     break;
                 }
                 else
@@ -882,7 +903,6 @@
                     injectInNode( btree, leafLevel.currentPage, levels, 1 );
 
                     // and we are done
-                    //System.out.println( leafLevel.currentPage );
                     break;
                 }
             }
@@ -899,28 +919,9 @@
      */
     private File flushToDisk( int fileNb, List<Tuple<K, V>> tuples, BTree<K, V> btree ) throws IOException
     {
-        //System.out.println( "Sorted values for file nb[" + fileNb + "] : " );
-
         // Sort the tuples. 
         Tuple<K, Set<V>>[] sortedTuples = sort( btree, tuples );
 
-        boolean isFirst = true;
-        for ( Tuple<K, Set<V>> tuple : sortedTuples )
-        {
-            if ( isFirst )
-            {
-                isFirst = false;
-            }
-            else
-            {
-                //System.out.print( ", " );
-            }
-
-            //System.out.print( tuple.getKey() );
-        }
-
-        //System.out.println();
-
         File file = File.createTempFile( "sorted", Integer.toString( fileNb ) );
         file.deleteOnExit();
         FileOutputStream fos = new FileOutputStream( file );
@@ -1130,7 +1131,6 @@
             while ( true )
             {
                 readTuples[i] = fetchTuple( btree, streams[i] );
-                //System.out.println( "Fetched tuple " + readTuples[i] + " from file " + i );
 
                 if ( readTuples[i] != null )
                 {
@@ -1139,7 +1139,6 @@
 
                     if ( !candidateSet.contains( candidate ) )
                     {
-                        //System.out.println( "Added candidate " + candidate + " to the set of candidates" );
                         candidateSet.add( candidate );
                         break;
                     }
@@ -1151,21 +1150,8 @@
             }
         }
 
-        int pos = 0;
-        Iterator<Tuple<K, Integer>> iterator = candidateSet.iterator();
-
-        while ( iterator.hasNext() )
-        {
-            Tuple<K, Integer> candidate = iterator.next();
-            //System.out.println( "candidate[" + pos + "] = " + candidate.getKey() );
-            pos++;
-        }
-
         Iterator<Tuple<K, Set<V>>> tupleIterator = new Iterator<Tuple<K, Set<V>>>()
         {
-            private int pos = 0;
-
-
             @Override
             public Tuple<K, Set<V>> next()
             {
@@ -1180,8 +1166,6 @@
 
                 // fetch it from the disk and store it into its reader
                 readTuples[tupleCandidate.value] = fetchTuple( btree, streams[tupleCandidate.value] );
-                //System.out.println( "Next : fetched new tuple from file nb " + tupleCandidate.value + " : "
-                //    + readTuples[tupleCandidate.value] );
 
                 if ( readTuples[tupleCandidate.value] != null )
                 {
@@ -1191,18 +1175,7 @@
                     candidateSet.add( newTuple );
                 }
 
-                int pos = 0;
-                Iterator<Tuple<K, Integer>> iterator = candidateSet.iterator();
-
-                while ( iterator.hasNext() )
-                {
-                    Tuple<K, Integer> candidate = iterator.next();
-                    //System.out.println( "candidate[" + pos + "] = " + candidate.getKey() );
-                    pos++;
-                }
-
                 // We can now return the found value
-                //System.out.println( "Returning selected tuple : " + tuple );
                 return tuple;
             }
 
diff --git a/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java b/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
index 1f8f2b2..e0b9dbf 100644
--- a/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
+++ b/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
@@ -149,128 +149,118 @@
     public void testPersistedBulkLoad10Elements() throws IOException, KeyNotFoundException,
         BTreeAlreadyManagedException
     {
-        for ( int i = 1000; i < 1001; i++ )
+        for ( int i = 0; i < 1001; i++ )
         {
-            System.out.println( "=======================================" );
-            System.out.println( "== Iteration #" + i );
-            System.out.println( "=======================================" );
             Random random = new Random( System.currentTimeMillis() );
             File file = File.createTempFile( "managedbtreebuilder", ".data" );
             file.deleteOnExit();
 
-            RecordManager rm = new RecordManager( file.getAbsolutePath() );
-            PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> ) rm.addBTree( "test",
-                LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
-
-            BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
-            int nbElems = i;
-            int addedElems = 0;
-
-            final Tuple<Long, String>[] elems = new Tuple[nbElems];
-            Map<Long, Tuple<Long, Set<String>>> expected = new HashMap<Long, Tuple<Long, Set<String>>>();
-
-            long t00 = System.currentTimeMillis();
-
-            while ( addedElems < nbElems )
+            try
             {
-                long key = random.nextLong() % 3333333L;
+                RecordManager rm = new RecordManager( file.getAbsolutePath() );
+                PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> ) rm.addBTree( "test",
+                    LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
 
-                if ( expected.containsKey( key ) )
+                BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
+                int nbElems = i;
+                int addedElems = 0;
+
+                final Tuple<Long, String>[] elems = new Tuple[nbElems];
+                Map<Long, Tuple<Long, Set<String>>> expected = new HashMap<Long, Tuple<Long, Set<String>>>();
+
+                long t00 = System.currentTimeMillis();
+
+                while ( addedElems < nbElems )
                 {
-                    continue;
+                    long key = random.nextLong() % 3333333L;
+
+                    if ( expected.containsKey( key ) )
+                    {
+                        continue;
+                    }
+
+                    long w = random.nextLong() % 3333333L;
+                    String value = "V" + w;
+                    elems[addedElems] = new Tuple<Long, String>( key, value );
+
+                    Tuple<Long, Set<String>> expectedTuple = expected.get( key );
+
+                    if ( expectedTuple == null )
+                    {
+                        expectedTuple = new Tuple<Long, Set<String>>( key, new TreeSet<String>() );
+                    }
+
+                    expectedTuple.value.add( value );
+                    expected.put( key, expectedTuple );
+                    addedElems++;
+
+                    if ( addedElems % 100 == 0 )
+                    {
+                        //System.out.println( "Nb added elements = " + addedElems );
+                    }
+                }
+                long t01 = System.currentTimeMillis();
+
+                // System.out.println( "Time to create the " + nbElems + " elements " + ( ( t01 - t00 ) / 1 ) );
+
+                Iterator<Tuple<Long, String>> tupleIterator = new Iterator<Tuple<Long, String>>()
+                {
+                    private int pos = 0;
+
+
+                    @Override
+                    public Tuple<Long, String> next()
+                    {
+                        return elems[pos++];
+                    }
+
+
+                    @Override
+                    public boolean hasNext()
+                    {
+                        return pos < elems.length;
+                    }
+
+
+                    @Override
+                    public void remove()
+                    {
+                    }
+                };
+
+                long t0 = System.currentTimeMillis();
+                BTree<Long, String> result = bulkLoader.load( btree, tupleIterator, 128 );
+                long t1 = System.currentTimeMillis();
+
+                System.out.println( "== Btree #" + i + ", Time to bulkoad the " + nbElems + " elements "
+                    + ( t1 - t0 ) + "ms" );
+
+                TupleCursor<Long, String> cursor = result.browse();
+                int nbFetched = 0;
+
+                long t2 = System.currentTimeMillis();
+
+                while ( cursor.hasNext() )
+                {
+                    Tuple<Long, String> elem = cursor.next();
+
+                    assertTrue( expected.containsKey( elem.key ) );
+                    Tuple<Long, Set<String>> tuple = expected.get( elem.key );
+                    assertNotNull( tuple );
+                    nbFetched++;
                 }
 
-                long w = random.nextLong() % 3333333L;
-                String value = "V" + w;
-                elems[addedElems] = new Tuple<Long, String>( key, value );
+                long t3 = System.currentTimeMillis();
 
-                //System.out.println( "Adding tuple : " + elems[i] );
+                //System.out.println( "Time to read the " + nbElems + " elements " + ( t3 - t2 ) );
+                assertEquals( nbElems, nbFetched );
 
-                Tuple<Long, Set<String>> expectedTuple = expected.get( key );
-
-                if ( expectedTuple == null )
-                {
-                    expectedTuple = new Tuple<Long, Set<String>>( key, new TreeSet<String>() );
-                }
-
-                expectedTuple.value.add( value );
-                expected.put( key, expectedTuple );
-                addedElems++;
-
-                if ( addedElems % 100 == 0 )
-                {
-                    //System.out.println( "Nb added elements = " + addedElems );
-                }
+                checkBtree( btree, result );
             }
-            long t01 = System.currentTimeMillis();
-
-            System.out.println( "Time to create the " + nbElems + " elements " + ( ( t01 - t00 ) / 1 ) );
-
-            Iterator<Tuple<Long, String>> tupleIterator = new Iterator<Tuple<Long, String>>()
+            finally
             {
-                private int pos = 0;
-
-
-                @Override
-                public Tuple<Long, String> next()
-                {
-                    return elems[pos++];
-                }
-
-
-                @Override
-                public boolean hasNext()
-                {
-                    return pos < elems.length;
-                }
-
-
-                @Override
-                public void remove()
-                {
-                }
-            };
-
-            long t0 = System.currentTimeMillis();
-            BTree<Long, String> result = bulkLoader.load( btree, tupleIterator, 65536 );
-            //rm.close();
-            //rm = new RecordManager( file.getAbsolutePath() );
-            //result.close();
-
-            //result = rm.getManagedTree( btree.getName() );
-            long t1 = System.currentTimeMillis();
-
-            System.out.println( "Time to bulkoad the " + nbElems + " elements " + ( ( t1 - t0 ) / 1 ) );
-
-            TupleCursor<Long, String> cursor = result.browse();
-            int nbFetched = 0;
-
-            long t2 = System.currentTimeMillis();
-
-            while ( cursor.hasNext() )
-            {
-                Tuple<Long, String> elem = cursor.next();
-
-                assertTrue( expected.containsKey( elem.key ) );
-                Tuple<Long, Set<String>> tuple = expected.get( elem.key );
-                assertNotNull( tuple );
-                nbFetched++;
-
-                //System.out.println( "Read tuple : " + tuple );
-                /*
-                for ( String value : elem.value )
-                {
-                    assertTrue( tuple.value.contains( value ) );
-                }
-                */
+                file.delete();
             }
-
-            long t3 = System.currentTimeMillis();
-
-            System.out.println( "Time to read the " + nbElems + " elements " + ( t3 - t2 ) );
-            assertEquals( nbElems, nbFetched );
-
-            checkBtree( btree, result );
         }
     }
 
@@ -426,47 +416,54 @@
         File file = File.createTempFile( "managedbtreebuilder", ".data" );
         file.deleteOnExit();
 
-        RecordManager rm = new RecordManager( file.getAbsolutePath() );
-        PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> ) rm.addBTree( "test",
-            LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
-
-        BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
-
-        int[] expectedNbPages = new int[]
-            {
-                0,
-                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
-        };
-
-        int[] expectedLimit = new int[]
-            {
-                0,
-                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-                0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 32,
-                16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 48
-        };
-
-        int[] expectedKeys = new int[]
-            {
-                0,
-                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-                9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-                16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
-        };
-
-        for ( int i = 0; i < 49; i++ )
+        try
         {
-            System.out.println( "=======================================" );
-            System.out.println( "== Iteration n#" + i );
-            System.out.println( "=======================================" );
+            RecordManager rm = new RecordManager( file.getAbsolutePath() );
+            PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> ) rm.addBTree( "test",
+                LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
 
-            BulkLoader<Long, String>.LevelInfo leafInfo = bulkLoader.computeLevel( btree, i, LevelEnum.LEAF );
+            BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
 
-            assertEquals( expectedNbPages[i], leafInfo.nbPages );
-            assertEquals( expectedLimit[i], leafInfo.nbElemsLimit );
-            assertEquals( expectedKeys[i], leafInfo.currentPage.getNbElems() );
+            int[] expectedNbPages = new int[]
+                {
+                    0,
+                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+                    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
+            };
+
+            int[] expectedLimit = new int[]
+                {
+                    0,
+                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+                    0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 32,
+                    16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 48
+            };
+
+            int[] expectedKeys = new int[]
+                {
+                    0,
+                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+                    9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+                    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
+            };
+
+            for ( int i = 0; i < 49; i++ )
+            {
+                System.out.println( "=======================================" );
+                System.out.println( "== Iteration n#" + i );
+                System.out.println( "=======================================" );
+
+                BulkLoader<Long, String>.LevelInfo leafInfo = bulkLoader.computeLevel( btree, i, LevelEnum.LEAF );
+
+                assertEquals( expectedNbPages[i], leafInfo.nbPages );
+                assertEquals( expectedLimit[i], leafInfo.nbElemsLimit );
+                assertEquals( expectedKeys[i], leafInfo.currentPage.getNbElems() );
+            }
+        }
+        finally
+        {
+            file.delete();
         }
     }
 
@@ -482,45 +479,52 @@
         File file = File.createTempFile( "managedbtreebuilder", ".data" );
         file.deleteOnExit();
 
-        RecordManager rm = new RecordManager( file.getAbsolutePath() );
-        PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> ) rm.addBTree( "test",
-            LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
-
-        BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
-
-        int[] expectedNbPages = new int[]
-            {
-                -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
-        };
-
-        int[] expectedLimit = new int[]
-            {
-                -1,
-                -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
-                0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 34,
-                17, 17, 17, 17, 17, 17, 17, 17, 34, 34, 34, 34, 34, 34, 34, 34, 51
-        };
-
-        int[] expectedKeys = new int[]
-            {
-                -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-                8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-                16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
-        };
-
-        for ( int i = 2; i < 52; i++ )
+        try
         {
-            System.out.println( "=======================================" );
-            System.out.println( "== Iteration n#" + i );
-            System.out.println( "=======================================" );
+            RecordManager rm = new RecordManager( file.getAbsolutePath() );
+            PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> ) rm.addBTree( "test",
+                LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
 
-            BulkLoader<Long, String>.LevelInfo nodeInfo = bulkLoader.computeLevel( btree, i, LevelEnum.NODE );
+            BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
 
-            assertEquals( expectedNbPages[i], nodeInfo.nbPages );
-            assertEquals( expectedLimit[i], nodeInfo.nbElemsLimit );
-            assertEquals( expectedKeys[i], nodeInfo.currentPage.getNbElems() );
+            int[] expectedNbPages = new int[]
+                {
+                    -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+                    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
+            };
+
+            int[] expectedLimit = new int[]
+                {
+                    -1,
+                    -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+                    0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 34,
+                    17, 17, 17, 17, 17, 17, 17, 17, 34, 34, 34, 34, 34, 34, 34, 34, 51
+            };
+
+            int[] expectedKeys = new int[]
+                {
+                    -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+                    8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+                    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
+            };
+
+            for ( int i = 2; i < 52; i++ )
+            {
+                System.out.println( "=======================================" );
+                System.out.println( "== Iteration n#" + i );
+                System.out.println( "=======================================" );
+
+                BulkLoader<Long, String>.LevelInfo nodeInfo = bulkLoader.computeLevel( btree, i, LevelEnum.NODE );
+
+                assertEquals( expectedNbPages[i], nodeInfo.nbPages );
+                assertEquals( expectedLimit[i], nodeInfo.nbElemsLimit );
+                assertEquals( expectedKeys[i], nodeInfo.currentPage.getNbElems() );
+            }
+        }
+        finally
+        {
+            file.delete();
         }
     }
 
@@ -536,46 +540,53 @@
         File file = File.createTempFile( "managedbtreebuilder", ".data" );
         file.deleteOnExit();
 
-        RecordManager rm = new RecordManager( file.getAbsolutePath() );
-        PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> ) rm.addBTree( "test",
-            LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
-
-        BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
-
-        int[] expectedNbPages = new int[]
-            {
-                -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
-        };
-
-        int[] expectedLimit = new int[]
-            {
-                -1,
-                -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
-                0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 34,
-                17, 17, 17, 17, 17, 17, 17, 17, 34, 34, 34, 34, 34, 34, 34, 34, 51
-        };
-
-        int[] expectedKeys = new int[]
-            {
-                -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-                8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-                16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
-        };
-
-        for ( int i = 2599; i <= 2599; i++ )
+        try
         {
-            System.out.println( "=======================================" );
-            System.out.println( "== Iteration #" + i );
-            System.out.println( "=======================================" );
+            RecordManager rm = new RecordManager( file.getAbsolutePath() );
+            PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> ) rm.addBTree( "test",
+                LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
 
-            List<BulkLoader<Long, String>.LevelInfo> levels = bulkLoader.computeLevels( btree, i );
+            BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
 
-            for ( BulkLoader<Long, String>.LevelInfo level : levels )
+            int[] expectedNbPages = new int[]
+                {
+                    -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+                    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
+            };
+
+            int[] expectedLimit = new int[]
+                {
+                    -1,
+                    -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+                    0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 34,
+                    17, 17, 17, 17, 17, 17, 17, 17, 34, 34, 34, 34, 34, 34, 34, 34, 51
+            };
+
+            int[] expectedKeys = new int[]
+                {
+                    -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+                    8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+                    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
+            };
+
+            for ( int i = 2599; i <= 2599; i++ )
             {
-                System.out.println( level );
+                System.out.println( "=======================================" );
+                System.out.println( "== Iteration #" + i );
+                System.out.println( "=======================================" );
+
+                List<BulkLoader<Long, String>.LevelInfo> levels = bulkLoader.computeLevels( btree, i );
+
+                for ( BulkLoader<Long, String>.LevelInfo level : levels )
+                {
+                    System.out.println( level );
+                }
             }
         }
+        finally
+        {
+            file.delete();
+        }
     }
 }