DC motor control with ramp and encoder as feedback. Code works almost

Hi,
with help of the encoder library I managed to read out a motor's encoder. 120000 counts is one revolution approx.
After hours and a small change in the library(adding a reset function) it's working. Speeding up and stopping where it should. However I tried to slow it done aswell. Now it is a hard break.
How can I slow it down? Somehow it needs to be dependent on the encoderPosition but I don't get it
In the commented loop it's slowing down but not stopping at the correct position as it just counts down the for-loop without any feedback and correction

/* Encoder Library - Basic Example
   http://www.pjrc.com/teensy/td_libs_Encoder.html

   This example code is in the public domain.
*/

#include <Encoder.h>
#define MOTOR_A_LEFT 7
#define MOTOR_A_RIGHT 8
#define MOTOR_A_PWM 9
//#define maxpwm 127




// Change these two numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder myEnc(2, 3);
//   avoid using pins with LEDs attached

void setup() {
  Serial.begin(115200);
  Serial.println("Basic Encoder Test:");
  pinMode(MOTOR_A_PWM, OUTPUT);
  pinMode(MOTOR_A_LEFT, OUTPUT);
  pinMode(MOTOR_A_RIGHT, OUTPUT);
  digitalWrite(MOTOR_A_LEFT, LOW); digitalWrite(MOTOR_A_RIGHT, LOW);
}


void loop() {

  m_move(120000);
  delay(2000);

}

void m_move(long m_endposition) {
  while (1) {
    long encoderPosition = myEnc.read();

    if (encoderPosition >= m_endposition) {
      m_stop();
      myEnc.reset();  //sets encoderPosition to 0
      Serial.println("end");
      break;
    }
    else {

      for (int i = 0; i < 256&&encoderPosition<20000; i++) {
        encoderPosition = myEnc.read();
        m_right(i);
        delay(5);
      }
 /*     
      for (int i = 255; i >0&&encoderPosition>100000; i--) {
        encoderPosition = myEnc.read();
        m_right(i);
        delay(5);
      }
*/
    }
  }
}


void m_links(int pwm) {
  analogWrite(MOTOR_A_PWM, pwm);
  digitalWrite(MOTOR_A_LEFT, HIGH); digitalWrite(MOTOR_A_RIGHT, LOW);
}
void m_right(int pwm) {
  analogWrite(MOTOR_A_PWM, pwm);
  digitalWrite(MOTOR_A_LEFT, LOW); digitalWrite(MOTOR_A_RIGHT, HIGH);
}
void m_stop() {
  digitalWrite(MOTOR_A_LEFT, LOW); digitalWrite(MOTOR_A_RIGHT, LOW);
}