 void lockedRotorCheck(){
     if (rpm <= LOCKEDDISCRPM){
         digitalWrite(STARTRELAYPIN, LOW); // immediately shut down if RPM lowByte
-        client.publish(TOPIC_T, "CritErr: Disc rotation is locked, attempting restart"); 
-		Serial.println("Disc motion has been stopped. Attempting Restart");
-		delay(10000);
-		motionControlStart();
-		}                            
-		
+        }                            
+        client.publish(TOPIC_T, "CritErr: Disc rotation is locked, attempting restart");              
 }
 
 void allStop(){
     digitalWrite(STARTRELAYPIN, LOW);
     Serial.println("System in All-Stop");
+    delay(5000);
     client.publish(TOPIC_T, "CritErr: System halted. All stop active. Restart Required");
     allStopVar = 1;
-    delay(10000);
+    loop();
     }    
 void exhibitStatusMsg(){
     char gs_msg [50];

/*                LOOP                 /
/**************************************/
void loop(){
	delay(3);
if  (allStopVar == 0){
    calculateRPM();
    discSlipCheck();
    lockedRotorCheck();
}
    now = millis();
    //MQTT Connection Check
	//if (!client.connected()) {
	//	reconnect();
    //}
    //client.loop();
}



void calculateRPM(){
if (millis() - prevMillis >= 5000){
    detachInterrupt(HALLSENSORPIN);              //disable interrupts while running calculate
    rpm = pulseCount * 6;          //converting frequency to RPM
    pulseCount = 0;                 //reset pulse counter
    prevMillis = millis();          //update prevMillis
    Serial.print("RPM: ");
    Serial.println(rpm);
    attachInterrupt(digitalPinToInterrupt(HALLSENSORPIN), sensorPulseCount, FALLING);
		}
  }

void motionControlStart(){
    Serial.println("Motor Control Start");
    if (restartCount < NUMBEROFRESTARTS){
        digitalWrite(STARTRELAYPIN, HIGH); // enable start relay if not above fail counter
        delay(5000); // wait for 2 second for a rotation 
        if (pulseCount == 0){               // if no rotation detected in interrupt
            digitalWrite(STARTRELAYPIN, LOW); // turn off motor becuase of no rotation
			Serial.println("No rotation detected -- attempting restart");
            restartCount++;
            delay (3000); // delay 3 seconds before attempting restart
            pulseCount = 0; // reset pulse count 
            motionControlStart();
            }
        if (pulseCount > 1){
        Serial.println("motion started, system running");
		delay(3000); 	// wait 3 seconds for disc to come up to fast enough speed
						// to not trip locked rotor functiion
		pulseCount = 0;
        restartCount = 0; // set restart counter to 0, since we're started
        allStopVar = 0; // Set allstop condition to off 
        }
