diff --git book_delete.module book_delete.module
index f0c82b1..b008913 100644
--- book_delete.module
+++ book_delete.module
@@ -130,22 +130,32 @@ function book_delete_delete($bid, &$context) {
     $context['sandbox']['highest_nid'] = 0;
     $context['sandbox']['bid'] = $bid;
   }
-  
-  // Delete 5 nodes at a time.  This needs to be set fairly low as there may be 
+ 
+  // Delete 5 nodes at a time.  This needs to be set fairly low as there may be
   // many search index deletions for each node.
   $limit = 5;
-  $result = db_query_range("SELECT nid FROM {book} WHERE bid = :bid AND nid > :nid AND nid <> bid ORDER BY nid ASC", 0, $limit, array(
+  
+  //DEFINE $nids!!!
+  $nids = db_query_range("SELECT nid FROM {book} WHERE bid = :bid AND nid > :nid AND nid <> bid ORDER BY nid ASC", 0, $limit, array(
     ':bid' => $context['sandbox']['bid'],
     ':nid' => $context['sandbox']['highest_nid'],
     ))->fetchCol();
+ 
   if (!empty($nids)) {
     node_delete_multiple($nids);
   }
-  
+ 
   // Update our progress information.
   $context['sandbox']['progress'] += count($nids);
-  $context['sandbox']['highest_nid'] = array_pop($nids);
-  
+ 
+
+  // don't let php produce a warning if the array is empty!
+  // let's say the book has 11 pages:
+  // the first 2 operations return populated $nids
+  // but the thirdone returns empty $nids:
+  // the only page left is the root page (nid = bid)!
+  $context['sandbox']['highest_nid'] = !empty($nids) ? array_pop($nids) : 0;
+ 
   // Delete the top book node last.
   if ($context['sandbox']['progress'] == $context['sandbox']['max'] - 1) {
     node_delete($context['sandbox']['bid']);
@@ -156,6 +166,12 @@ function book_delete_delete($bid, &$context) {
   if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
     $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
   }
+  else {
+     
+	  // inform that we are done otherwise we are entering in a eternal loop(!)
+      // becouse the $context['finished'] will never equals 1!!!
+      $context['finished'] = 1;
+  }
 }
 
 /**
