Index: src/pitch/pitchyin.c
===================================================================
--- src/pitch/pitchyin.c	(revision 482641dfc6c50215aba77293bf5de6143e24e983)
+++ src/pitch/pitchyin.c	(revision 3e48568b094d6dbc6310a445ec4afd79f7f53da3)
@@ -37,5 +37,5 @@
   fvec_t *yin;
   smpl_t tol;
-  smpl_t confidence;
+  uint_t peak_pos;
 };
 
@@ -68,4 +68,5 @@
   o->yin = new_fvec (bufsize / 2);
   o->tol = 0.15;
+  o->peak_pos = 0;
   return o;
 }
@@ -157,17 +158,16 @@
     if (tau > 4 && (yin_data[period] < tol) &&
         (yin_data[period] < yin_data[period + 1])) {
-      out->data[0] = fvec_quadratic_peak_pos (yin, period);
-      goto beach;
+      o->peak_pos = (uint_t)period;
+      out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
+      return;
     }
   }
-  out->data[0] = fvec_quadratic_peak_pos (yin, fvec_min_elem (yin));
-beach:
-  return;
+  o->peak_pos = (uint_t)fvec_min_elem (yin);
+  out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
 }
 
 smpl_t
 aubio_pitchyin_get_confidence (aubio_pitchyin_t * o) {
-  o->confidence = 1. - fvec_min (o->yin);
-  return o->confidence;
+  return 1. - o->yin->data[o->peak_pos];
 }
 
Index: src/pitch/pitchyinfast.c
===================================================================
--- src/pitch/pitchyinfast.c	(revision 482641dfc6c50215aba77293bf5de6143e24e983)
+++ src/pitch/pitchyinfast.c	(revision 3e48568b094d6dbc6310a445ec4afd79f7f53da3)
@@ -39,5 +39,5 @@
   fvec_t *yin;
   smpl_t tol;
-  smpl_t confidence;
+  uint_t peak_pos;
   fvec_t *tmpdata;
   fvec_t *sqdiff;
@@ -60,4 +60,5 @@
   o->fft = new_aubio_fft (bufsize);
   o->tol = 0.15;
+  o->peak_pos = 0;
   return o;
 }
@@ -86,5 +87,4 @@
   uint_t W = o->yin->length; // B / 2
   fvec_t tmp_slice, kernel_ptr;
-  smpl_t *yin_data = yin->data;
   uint_t tau;
   sint_t period;
@@ -143,13 +143,13 @@
     // compute square difference r_t(tau) = sqdiff - 2 * r_t_tau[W-1:-1]
     for (tau = 0; tau < W; tau++) {
-      yin_data[tau] = o->sqdiff->data[tau] - 2. * rt_of_tau->data[tau+W];
+      yin->data[tau] = o->sqdiff->data[tau] - 2. * rt_of_tau->data[tau+W];
     }
   }
 
   // now build yin and look for first minimum
-  fvec_set_all(out, 0.);
-  yin_data[0] = 1.;
+  fvec_zeros(out);
+  yin->data[0] = 1.;
   for (tau = 1; tau < length; tau++) {
-    tmp2 += yin_data[tau];
+    tmp2 += yin->data[tau];
     if (tmp2 != 0) {
       yin->data[tau] *= tau / tmp2;
@@ -158,19 +158,19 @@
     }
     period = tau - 3;
-    if (tau > 4 && (yin_data[period] < tol) &&
-        (yin_data[period] < yin_data[period + 1])) {
-      out->data[0] = fvec_quadratic_peak_pos (yin, period);
-      goto beach;
+    if (tau > 4 && (yin->data[period] < tol) &&
+        (yin->data[period] < yin->data[period + 1])) {
+      o->peak_pos = (uint_t)period;
+      out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
+      return;
     }
   }
-  out->data[0] = fvec_quadratic_peak_pos (yin, fvec_min_elem (yin) );
-beach:
-  return;
+  // use global minimum 
+  o->peak_pos = (uint_t)fvec_min_elem (yin);
+  out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
 }
 
 smpl_t
 aubio_pitchyinfast_get_confidence (aubio_pitchyinfast_t * o) {
-  o->confidence = 1. - fvec_min (o->yin);
-  return o->confidence;
+  return 1. - o->yin->data[o->peak_pos];
 }
 
Index: src/pitch/pitchyinfft.c
===================================================================
--- src/pitch/pitchyinfft.c	(revision 482641dfc6c50215aba77293bf5de6143e24e983)
+++ src/pitch/pitchyinfft.c	(revision 3e48568b094d6dbc6310a445ec4afd79f7f53da3)
@@ -37,5 +37,5 @@
   fvec_t *yinfft;     /**< Yin function */
   smpl_t tol;         /**< Yin tolerance */
-  smpl_t confidence;  /**< confidence */
+  uint_t peak_pos;    /**< currently selected peak pos*/
   uint_t short_period; /** shortest period under which to check for octave error */
 };
@@ -68,4 +68,5 @@
   p->yinfft = new_fvec (bufsize / 2 + 1);
   p->tol = 0.85;
+  p->peak_pos = 0;
   p->win = new_aubio_window ("hanningz", bufsize);
   p->weight = new_fvec (bufsize / 2 + 1);
@@ -162,9 +163,11 @@
       halfperiod = FLOOR (tau / 2 + .5);
       if (yin->data[halfperiod] < p->tol)
-        output->data[0] = fvec_quadratic_peak_pos (yin, halfperiod);
+        p->peak_pos = halfperiod;
       else
-        output->data[0] = fvec_quadratic_peak_pos (yin, tau);
+        p->peak_pos = tau;
+      output->data[0] = fvec_quadratic_peak_pos (yin, p->peak_pos);
     }
   } else {
+    p->peak_pos = 0;
     output->data[0] = 0.;
   }
@@ -186,6 +189,5 @@
 smpl_t
 aubio_pitchyinfft_get_confidence (aubio_pitchyinfft_t * o) {
-  o->confidence = 1. - fvec_min (o->yinfft);
-  return o->confidence;
+  return 1. - o->yinfft->data[o->peak_pos];
 }
 
