diff --git a/sm5/VERSION b/sm5/VERSION
index 45a4fb75db864000d01701c0f7a51864bd4daabf..ec635144f60048986bc560c5576355344005e6e7 100644
--- a/sm5/VERSION
+++ b/sm5/VERSION
@@ -1 +1 @@
-8
+9
diff --git a/sm5/atacmds.c b/sm5/atacmds.c
index f7051591635aad274e28f85cdd9607feda642464..bc575d9174edbbe826ef52b7f62878071c755f85 100644
--- a/sm5/atacmds.c
+++ b/sm5/atacmds.c
@@ -1,4 +1,4 @@
-//  $Id: atacmds.c,v 1.5 2002/10/14 15:26:05 ballen4705 Exp $
+//  $Id: atacmds.c,v 1.6 2002/10/15 08:58:40 ballen4705 Exp $
 /*
  * atacmds.c
  *
@@ -486,22 +486,20 @@ int isSupportSelfTest (struct ata_smart_values data)
 }
 
 
-int ataCheckSmart ( struct ata_smart_values data, struct ata_smart_thresholds thresholds)
-{
-   int i;
+// Loop over all valid attributes.  If they are prefailure attributes
+// and are below the threshold value, then return the index of the
+// lowest failing attribute.  Return 0 if all prefailure attributes
+// are in bounds.
+int ataCheckSmart (struct ata_smart_values data, struct ata_smart_thresholds thresholds){
+  int i;
   
-   for ( i = 0 ; i < 30 ; i++ )
-   {
-      if ( (data.vendor_attributes[i].id !=0) &&   
-           (thresholds.thres_entries[i].id != 0) &&
-           (data.vendor_attributes[i].status.flag.prefailure) &&
-           (data.vendor_attributes[i].current <
-             thresholds.thres_entries[i].threshold) &&
-           (thresholds.thres_entries[i].threshold != 0xFE) )
-      {
-         return i;
-      }
-   }
-
-   return 0;
+  for (i = 0; i < NUMBER_ATA_SMART_ATTRIBUTES; i++){
+    if (data.vendor_attributes[i].id &&   
+	thresholds.thres_entries[i].id &&
+	data.vendor_attributes[i].status.flag.prefailure &&
+	(data.vendor_attributes[i].current < thresholds.thres_entries[i].threshold) &&
+	(thresholds.thres_entries[i].threshold != 0xFE))
+      return i;
+  }
+  return 0;
 }
diff --git a/sm5/atacmds.cpp b/sm5/atacmds.cpp
index 241cf8ee86e7bea75a96ba2c4fa4a0877f172644..8ab7821931d0b79dfbe2fed20991b547373799a0 100644
--- a/sm5/atacmds.cpp
+++ b/sm5/atacmds.cpp
@@ -1,4 +1,4 @@
-//  $Id: atacmds.cpp,v 1.5 2002/10/14 15:26:05 ballen4705 Exp $
+//  $Id: atacmds.cpp,v 1.6 2002/10/15 08:58:40 ballen4705 Exp $
 /*
  * atacmds.c
  *
@@ -486,22 +486,20 @@ int isSupportSelfTest (struct ata_smart_values data)
 }
 
 
-int ataCheckSmart ( struct ata_smart_values data, struct ata_smart_thresholds thresholds)
-{
-   int i;
+// Loop over all valid attributes.  If they are prefailure attributes
+// and are below the threshold value, then return the index of the
+// lowest failing attribute.  Return 0 if all prefailure attributes
+// are in bounds.
+int ataCheckSmart (struct ata_smart_values data, struct ata_smart_thresholds thresholds){
+  int i;
   
-   for ( i = 0 ; i < 30 ; i++ )
-   {
-      if ( (data.vendor_attributes[i].id !=0) &&   
-           (thresholds.thres_entries[i].id != 0) &&
-           (data.vendor_attributes[i].status.flag.prefailure) &&
-           (data.vendor_attributes[i].current <
-             thresholds.thres_entries[i].threshold) &&
-           (thresholds.thres_entries[i].threshold != 0xFE) )
-      {
-         return i;
-      }
-   }
-
-   return 0;
+  for (i = 0; i < NUMBER_ATA_SMART_ATTRIBUTES; i++){
+    if (data.vendor_attributes[i].id &&   
+	thresholds.thres_entries[i].id &&
+	data.vendor_attributes[i].status.flag.prefailure &&
+	(data.vendor_attributes[i].current < thresholds.thres_entries[i].threshold) &&
+	(thresholds.thres_entries[i].threshold != 0xFE))
+      return i;
+  }
+  return 0;
 }
diff --git a/sm5/smartmontools.spec b/sm5/smartmontools.spec
index 1933de0a1e4b464287c09630ed0f1b11b53cee50..fb15aa7a8c3a6161d8e8e4929a893b6f2e33b841 100644
--- a/sm5/smartmontools.spec
+++ b/sm5/smartmontools.spec
@@ -1,4 +1,4 @@
-Release:  7
+Release:  8
 Summary:	SMARTmontools - for monitoring S.M.A.R.T. disks and devices
 Name:		smartmontools
 Version:	5.0