--- jitterbuf.c
+++ jitterbuf.c
@@ -118,45 +118,66 @@
 }
 #endif
 
-/*!	\brief simple history manipulation 
- 	\note maybe later we can make the history buckets variable size, or something? */
-/* drop parameter determines whether we will drop outliers to minimize
- * delay */
-static int history_put(jitterbuf *jb, long ts, long now, long ms) 
+static int check_resync(jitterbuf *jb, long ts, long now, long ms, const enum jb_frame_type type, long *delay) 
 {
-	long delay = now - (ts - jb->info.resync_offset);
+	long numts = 0;
 	long threshold = 2 * jb->info.jitter + jb->info.conf.resync_threshold;
-	long kicked;
 
-	/* don't add special/negative times to history */
-	if (ts <= 0) 
-		return 0;
+       /* Check for overfill of the buffer */
+	if (jb->frames) {
+		numts = jb->frames->prev->ts - jb->frames->ts;
+	}
 
+	if (numts >= (jb->info.conf.max_jitterbuf)) {
+		if (!jb->dropem) {
+			ast_debug(1, "Attempting to exceed Jitterbuf max %ld timeslots\n",
+				jb->info.conf.max_jitterbuf);
+			jb->dropem = 1;
+		}
+		jb->info.frames_dropped++;
+		return -1;
+	} else {
+		jb->dropem = 0;
+	}
+	
 	/* check for drastic change in delay */
 	if (jb->info.conf.resync_threshold != -1) {
-		if (abs(delay - jb->info.last_delay) > threshold) {
+		if (abs(*delay - jb->info.last_delay) > threshold) {
 			jb->info.cnt_delay_discont++;
-			if (jb->info.cnt_delay_discont > 3) {
-				/* resync the jitterbuffer */
+			if ((jb->info.cnt_delay_discont > 3) || (type != JB_TYPE_VOICE)) {
+				/* resync the jitterbuffer, immediately if not a voice frame*/
 				jb->info.cnt_delay_discont = 0;
 				jb->hist_ptr = 0;
 				jb->hist_maxbuf_valid = 0;
-
-				jb_warn("Resyncing the jb. last_delay %ld, this delay %ld, threshold %ld, new offset %ld\n", jb->info.last_delay, delay, threshold, ts - now);
+				jb_warn("Resyncing the jb. last_delay %ld, this delay %ld, threshold %ld, new offset %ld\n", jb->info.last_delay, *delay, threshold, ts - now);
 				jb->info.resync_offset = ts - now;
-				jb->info.last_delay = delay = 0; /* after resync, frame is right on time */
+				jb->info.last_delay = *delay = 0; /* after resync, frame is right on time */
 			} else {
 				return -1;
 			}
 		} else {
-			jb->info.last_delay = delay;
+			jb->info.last_delay = *delay;
 			jb->info.cnt_delay_discont = 0;
 		}
 	}
+	return 0;
+}
+
+/*!	\brief simple history manipulation 
+ 	\note maybe later we can make the history buckets variable size, or something? */
+/* drop parameter determines whether we will drop outliers to minimize
+ * delay */
+static int history_put(jitterbuf *jb, long ts, long now, long ms, long *delay) 
+{
+	long kicked;
+	
+	/* don't add special/negative times to history */
+	if (ts <= 0) 
+		return 0;
 
 	kicked = jb->history[jb->hist_ptr % JB_HISTORY_SZ];
 
-	jb->history[(jb->hist_ptr++) % JB_HISTORY_SZ] = delay;
+	jb->history[(jb->hist_ptr++) % JB_HISTORY_SZ] = *delay;
 
 	/* optimization; the max/min buffers don't need to be recalculated, if this packet's
 	 * entry doesn't change them.  This happens if this packet is not involved, _and_ any packet
@@ -172,11 +193,11 @@
 		goto invalidate;
 
 	/* if the new delay would go into min */
-	if (delay < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])
+	if (*delay < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])
 		goto invalidate;
 
 	/* or max.. */
-	if (delay > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])
+	if (*delay > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])
 		goto invalidate;
 
 	/* or the kicked delay would be in min */
@@ -506,35 +527,19 @@
 
 enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, long ts, long now) 
 {
-	long numts;
 
 	jb_dbg2("jb_put(%x,%x,%ld,%ld,%ld)\n", jb, data, ms, ts, now);
-
-	numts = 0;
-	if (jb->frames)
-		numts = jb->frames->prev->ts - jb->frames->ts;
-
-	/*
-	if (numts >= jb->info.conf.max_jitterbuf) {
-		if (!jb->dropem) {
-			ast_debug(1, "Attempting to exceed Jitterbuf max %ld timeslots\n",
-				jb->info.conf.max_jitterbuf);
-			jb->dropem = 1;
-		}
+	long delay = now - (ts - jb->info.resync_offset);
+	
+	if (check_resync(jb,ts,now,ms,type,&delay)) {
 		jb->info.frames_dropped++;
 		return JB_DROP;
-	} else {
-		jb->dropem = 0;
 	}
-	*/
 
 	if (type == JB_TYPE_VOICE) {
 		/* presently, I'm only adding VOICE frames to history and drift calculations; mostly because with the
 		 * IAX integrations, I'm sending retransmitted control frames with their awkward timestamps through */
-		if (history_put(jb,ts,now,ms)) {
-			jb->info.frames_dropped++;
-			return JB_DROP;
-		}
+		history_put(jb,ts,now,ms,&delay);
 	}
 
 	jb->info.frames_in++;
