     findSensor(max(maxPulse, endpulse));
 }
 
-int timedTurn(int halfturns, unsigned long duration, bool dir) {
+int timedTurn(int halfturns, long duration, bool dir) {
+    // adjust duration
+    duration = (duration + timedTurnAdd) * timedTurnMul;
+    if (duration < minimumDuration)
+        return 0;
     int fullspeedsteps = (halfTurnSteps * halfturns) - (accelSteps * 2);
-    unsigned long pulse = ((duration * 1000L) - (maxPulse * accelSteps)) /
-                          (accelSteps + fullspeedsteps);
+    long acceltime = (long)maxPulse * (long)accelSteps;
+    long turnduration = (duration * 1000L) - acceltime;
+    long pulse = turnduration / (accelSteps + fullspeedsteps);
     int accelsteps = accelSteps;
     if (pulse > maxPulse) {
         accelsteps = 0;

    return glisstime;
}

void durationTurn(unsigned long duration, float pitch, bool dir, bool recentre) {
    _durationGliss(duration, pitch, pitch, 0, 0, dir, recentre);
}

long durationGliss(unsigned long duration, float startpitch, float endpitch,
        bool dir, bool recentre, int sustain) {
    return _durationGliss(duration, startpitch, endpitch, sustain, sustain, dir, recentre);
}

long doubleGliss(int durationone, int durationtwo,
        float startpitch, float midpitch, float endpitch,
        int sustainstart, int sustainmid, int sustainend,
        bool dir, bool recentre) {
    int startpulse = pitchToPulse(startpitch + glissAdd);
    int midpulse = pitchToPulse(midpitch + glissAdd);
    int endpulse = pitchToPulse(endpitch + glissAdd);
    int accelsteps = map(startpitch, 48, 72, accelSteps-10, accelSteps+10);
    int decelsteps = map(endpitch, 48, 72, accelSteps-10, accelSteps+10);
    unsigned long glissonetime = ((durationone - sustainstart) * 1000L) -
        ((max(maxPulse, startpulse) + startpulse) * (accelsteps / 2));
    glissonetime = max(0, (glissonetime * durationGlissMul) + (durationGlissAdd * 1000L));
    int glissonesteps = glissonetime / ((startpulse + midpulse) / 2);
    unsigned long glisstwotime = ((durationtwo - sustainstart) * 1000L) -
        ((endpulse + max(maxPulse, endpulse)) * (decelsteps / 2));
    glisstwotime = max(0, (glisstwotime * durationGlissMul) + (durationGlissAdd * 1000L));
    int glisstwosteps = glisstwotime / ((midpulse + endpulse) / 2);
    int startsustainpulse = pitchToPulse(startpitch + glissAdd - 1);
    int sustainstartsteps = (sustainstart * 1000L) / startsustainpulse;

char newDuration[rDurlength];
char newSustainDuration[rDurlength];
int halfTurns;
long Duration;
long midDuration;
long sustainDuration;
float startPitch;
float midPitch;
float endPitch;
