 	tmp_serial_out[0] = 0;
 
 	if (tmp_str[i + 1] == 'S' || tmp_str[i + 1] == 's') { // gets stepper motor speed and acceleration num sensors attached
-		byte motor_index;
+		int8_t motor_index;
 		byte num_sensors_attached;
 		float motor_speed, motor_acceleration;
-		int num_read = sscanf(tmp_str + i + 2, "%u", &motor_index);
-		steppers_controller.get_speed_and_acceleration(motor_index, &motor_speed, &motor_acceleration);
+		int num_read = sscanf(tmp_str + i + 2, "%hhu", &motor_index);
+		if (num_read != 1) {
+			strcpy(tmp_serial_out, "E#");
+			i += 2;
+			return;
+		}		steppers_controller.get_speed_and_acceleration(motor_index, &motor_speed, &motor_acceleration);
 		num_sensors_attached = steppers_controller.get_num_attached_sensors(motor_index);
 		sprintf(tmp_serial_out, "GS%d %d %d %u#", motor_index, (int)motor_speed, (int)motor_acceleration, num_sensors_attached);
 		i += 4;

		}
		else
			if (tmp_str[j] == 'I' || tmp_str[j] == 'i') {// infrared
				int sensor_index;
				int num_read = sscanf(tmp_str + j + 1, "%d", &sensor_index);
				if (motor_type == 'S' || motor_type == 's') // attach to stepper motors controller
					steppers_controller.add_sensor(motor_index, INFRARED_ANALOG, sensor_index, 0, 0, 0, 0);
				else

		else
			// button
			if (tmp_str[i + 1] == 'B' || tmp_str[i + 1] == 'b') {
				uint8_t sensor_index;
				int num_read = sscanf(tmp_str + i + 2, "%hhu", &sensor_index);
				if (num_read != 1) {
					strcpy(tmp_serial_out, "E#");
					i += 2;
					return;
				}
				// Serial.println(sensor_index);
				int sensor_value = buttons_controller.get_state(sensor_index);
				sprintf(tmp_serial_out, "RB%d %d#", sensor_index, sensor_value);
