Passive Radar platform using Stepper and Rotary encoder

The desired functionality is achieved with the following code.

#include <Stepper.h>
#include <Encoder.h>

#define ENC_A 2
#define ENC_B 3

// Define number of steps per revolution:
const int stepsPerRevolution = 200;

#define pwmA 3
#define pwmB 11
#define brakeA 9
#define brakeB 8
#define dirA 12
#define dirB 13

// Initialize the stepper library on the motor shield:
Stepper myStepper = Stepper(stepsPerRevolution, dirA, dirB);

Encoder encoder(ENC_A, ENC_B);

long previousEncoderValue = 0;
int encoderDirection = 1;  // 1 for forward, -1 for backward

// Define variables for min and max encoder values
int min_encoder_value = -100;
int max_encoder_value = 100;

void setup() {
  // Set the PWM and brake pins so that the direction pins can be used to control the motor:
  pinMode(pwmA, OUTPUT);
  pinMode(pwmB, OUTPUT);
  pinMode(brakeA, OUTPUT);
  pinMode(brakeB, OUTPUT);

  digitalWrite(pwmA, HIGH);
  digitalWrite(pwmB, HIGH);
  digitalWrite(brakeA, LOW);
  digitalWrite(brakeB, LOW);

  // Set the motor speed (RPMs):
  myStepper.setSpeed(30);

  Serial.begin(9600);
}

void loop() {
  long encoderValue = encoder.read();

  // Check if the encoder value is within the specified range
  if (encoderValue >= max_encoder_value) {
    encoderDirection = -1;  // Change direction to backward
  } else if (encoderValue <= min_encoder_value) {
    encoderDirection = 1;  // Change direction to forward
  }

  // Rotate stepper motor based on encoder direction
  myStepper.step(encoderDirection * 800);
}

However, I'm still facing an issue where the stepper begins to stutter once the encoder is turned. Additionally, when the encoder reaches its maximum or minimum values, the stepper starts turning in the opposite direction as expected.

I've experimented with debounce delays ranging up to 1000ms, but haven't observed any improvements. Does anyone have any suggestions on how to prevent the stepper from stuttering when the encoder is rotated?