     default:
       break;
   }
-}    
-
-
-void boxcar_addValue(int add,int set){
-    int offset = set*MovingAverageWidth;
-    if(boxcar_index[set] == MovingAverageWidth+offset){
-        boxcar_index[set] = 0;
-        boxcar[boxcar_index[set]+offset] = add/MovingAverageWidth;
-    } else{
-        boxcar_index[set]++;
-        boxcar[boxcar_index[set]+offset] = add/MovingAverageWidth;
-    }    
-}
-        
-
-int boxcarGetAverage(int set) {
-    int mean = 0;
-    int offset = set*MovingAverageWidth;
-    for (int i =0; i < MovingAverageWidth; i++){
-        mean = mean + boxcar[i+offset];       
-    }    
-    return mean;
+}
+
+
+void boxcar_addValue(int add, struct boxcar *data) {
+
+  if (data-> index == MovingAverageWidth) {
+    data-> index = 0;
+    data->vals[data-> index] = add;
+  } else {
+    data-> index++;
+    data->vals[data-> index] = add;
+  }
+}
+
+
+int boxcarGetAverage(struct boxcar *data) {
+  int mean = 0;
+  for (int i = 0; i < MovingAverageWidth; i++) {
+    mean = mean + data->vals[i];
+  }
+  return mean;
 }
 
 struct w calculateWall(int xnaught, int xone,  struct w wall) {

#define Function_2	56
#define Function_3      57

//object instantition 
Servo Driveleft;
Servo Driveright;
Servo Turret;

};

struct boxcar {
  int vals[NoAverageDataSets];
  int index;
  int delta;
};
