Problem with Servo and Encoder

    delay(50);

Not a good idea. This will cause it to miss encoder steps.