 }
 
 void loop() {
+    /*
     if (DEBUG) {  
       digitalWrite(GREENLED, digitalState(LIMIT_SW));     // glow when free. in loop 
       digitalWrite(REDLED, digitalState(LIMIT_ARM));      // glow when free. in loop
     }
+    */
     
     // only handles limiting if bin is mostly empty
-    if ((liftState == HIGH) && (stepperLift.targetPosition() < 0)) {
-      delay(5);                                    // de-bounce the switch hopefully
+    if ((liftState == HIGH) && !BACKINGOFF) {
+      delay(3);                             // de-bounce the switch hopefully
       if (digitalState(LIMIT_SW)) {
         stepperLift.setCurrentPosition(0);
-        delay(3);                                 // deceleration 
         stepperLift.moveTo(liftBackOff);
         BACKINGOFF = true;
-        timeStart = millis();
         UPDATE = true;
         liftState = LOW;
       }
     }
-    else if ((!liftState) && ((timeStart - millis()) > 1900))    // deals with limit-switch hysterysis
+    else if (BACKINGOFF && !liftState) {   // deals with limit-switch hysterysis
       BACKINGOFF = false;
-    else if ((liftState == HIGH) && (!BACKINGOFF)) {          // stopping for unforseen reasons
-      delay(4);                                               // de-bounce
-      if (digitalState(LIMIT_SW)) {
-        stepperLift.stop();                                  // stop at maximum deceleration
-        UPDATE = true;                                      // report position
-        liftState = LOW;
-      }
-    }
+      liftBackOff = stepperLift.currentPosition();
+      if (liftBackOff < 1)
+        Serial.println("WARNING  WARNING  error with liftBackOff");
+      stepperLift.setCurrentPosition(0);
+    }
+      
     
     // arm starts off moving towards limit switch in setup(), hits it, moves to ready-to-load         
     if ((armState == HIGH) && (stepperArm.targetPosition() < 0)){

      }
      else if (inputString == "99") {        // 'c' unidentified pile
        stepperArm.moveTo(secondArmPos);
        destinationArmPos = firstArmPos;
      }
      else if (inputString == "100") {       // 'd' Reset into loading mode until another character sent
        stepperArm.moveTo(firstArmPos);

      UPDATE = true;
      oldAnalog1 = newAnalog1;
    }
    else if (abs(oldAnalog2 - newAnalog2) > 30) {
      UPDATE = true;
      oldAnalog2 = newAnalog2;
    }
        
    if (abs(myserv.read() - oldServoPos) > 1) {
      UPDATE = true;
      oldServoPos = myserv.read();
    }
        
    if (UPDATE) {
        Serial.print("Liftpos: " + String(stepperLift.currentPosition()) + " Armpos: " + String(stepperArm.currentPosition()));
        Serial.println("  A0: " + String(newAnalog1) + "  A1: " + String(newAnalog2) + " srvo: " + String(oldServoPos) + " tm:" + String(millis()));
        UPDATE = false;
    }
    
    if (!digitalState(LIMIT_SW) || BACKINGOFF)
      stepperLift.run();
    stepperArm.run(); 
     
    // first character sent switches us into LOADED mode
    // 97="a", 98="b", 99="c", 100="d"                                
