 			if(pendingTags.length == 0)
 				return super.bufferLength;
 
-			// Get active range of pending tags.
-			var minTime:Number = Number.MAX_VALUE, maxTime:Number = 0.0;
-			for(var i:int=0; i<pendingTags.length; i++)
-			{
-				var curTag:FLVTag = pendingTags[i];
-				var curTime:Number = curTag.timestamp;
-				if(curTime < minTime)
-					minTime = curTime;
-				if(curTime > maxTime)
-					maxTime = curTime;
-			}
-
+			// Get active range of pending tags. Since we keep them sorted this is easy.
+			var minTime:Number = pendingTags[0].timestamp
+			var maxTime:Number = pendingTags[pendingTags.length - 1].timestamp;
 			var len:Number = (maxTime - minTime) / 1000 + super.bufferLength;
-			trace("CALCULATED LENGTH TO BE " + len + " (" + (maxTime/1000) + " , " + (minTime/1000) + ", " + super.bufferLength + ")");
+			//trace("CALCULATED LENGTH TO BE " + len + " (" + (maxTime/1000) + " , " + (minTime/1000) + ", " + super.bufferLength + ")");
 			return len;
 		}
 
 
+
 		private function onBufferTag(tag:FLVTag):Boolean
 		{
 			trace("Got tag " + tag);
+
 			// Do filter logic here.
 
-			// Add to the queue.
+			// Add to the queue, marking if we need to resort.
+			if(pendingTags.length > 0 
+				&& tag.timestamp < pendingTags[pendingTags.length-1].timestamp)
+				needPendingSort = true;
 			pendingTags.push(tag);
 
 			return true;
+		}
+
+		// Reset the pending buffer actions.
+		private function flushPendingTags():void
+		{
+			trace("FLUSHING PENDING TAGS");
+			pendingTags.length = 0;
+			endAfterPending = false;
+			needPendingSort = false;
 		}
 
 		/**

						logger.error("I think I should reset playback.");
					}
					appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);
				}
			}


			if(super.bufferLength >= bufferFeedMin)
				return;

			// We want to keep the actual required buffer short so we don't stall with
			// tags still pending.
			super.bufferTime = bufferFeedMin;

			// Append tag bytes until we've hit our time buffer goal.
			var curTagOffset:int = 0;
			while(super.bufferLength <= (bufferFeedMin + bufferFeedAmount)
			      && (pendingTags.length - curTagOffset) > 0)
			{
				// Append some tags.
