         leftDir = 0;
       }
     }
-    if((leftDistance <= maximumRange && leftDistance >= minimumRange) &&
-       (rightDistance <= maximumRange && rightDistance >=minimumRange)) {
+    if((leftDistance <= maxRange && leftDistance >= minRange) &&
+       (rightDistance <= maxRange && rightDistance >=minRange)) {
         found = true;
         //Serial.println("FOUND");
       stop();  

 }
}

void checkLine() {
  if((frontVal - frontBaseVal) >= lineThreshold) {
    recovery(1);
    return;
  }
  if((leftVal - leftBaseVal) >= lineThreshold) {
    recovery(2);
    return;
  }
  if((rightVal - rightBaseVal) >= lineThreshold) {
    recovery(3);
    return;
  }
}

void recovery(int sensor) {
  // 0 is forward, 1 is backward
  //move(1, 200, rightDir); //right motor
  //move(2, 200, leftDir); //left motor
  switch(sensor) {
    case 1:   //front, burst of back up
      Serial.println("FRONT TRIGGERED");
      move(1, 255, 1);
      move(2, 255, 1);
      delay(1000);
      break;  //left, burst forward, back up to right
    case 2:
      Serial.println("LEFT TRIGGERED");
      move(1, 255, 0);
      move(2, 255, 0);
      delay(500);
      move(1, 128, 1);
      move(2, 255, 1);
      delay(500);
      break;
    case 3:   //right, burst forward, back up to left
      Serial.println("RIGHT TRIGGERED");
      move(1, 255, 1);
      move(2, 255, 1);
      delay(500);
      move(2, 128, 1);
      move(1, 255, 1);
      delay(500);
      break;
  }
}

void move(int motor, int speed, int direction){
//Move specific motor at speed and direction
//motor: 0 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise
 digitalWrite(STBY, HIGH); //disable standby

 boolean inPin1 = LOW;
 boolean inPin2 = HIGH;

 if(direction == 1){
   inPin1 = HIGH;
   inPin2 = LOW;
 }

 if(motor == 1){
   digitalWrite(AIN1, inPin1);
   digitalWrite(AIN2, inPin2);
   analogWrite(PWMA, speed);
 }else{
   digitalWrite(BIN1, inPin1);
   digitalWrite(BIN2, inPin2);
   analogWrite(PWMB, speed);
 }
}

void stop(){
//enable standby  
  digitalWrite(STBY, LOW); 
}

void calcDistance() {
 prevLeft = leftDistance;
 prevRight = rightDistance;

  }
}

//follow
void follow() {
  while(!tagged) {
    calcDistance();
    diff = leftDistance - rightDistance;
    diffMag = abs(diff);

    if(!(leftDistance <= maxRange && leftDistance >= minRange) &&
       !(rightDistance <= maxRange && rightDistance >=minRange)) {
        found = false;
        lost = true;
        search();
