 		private var bufferFeedMin:Number = 0.25; // How many seconds to actually keep fed into the native buffer.
 		private var bufferFeedAmount:Number = 0.1; // How many seconds of data to feed when we feed.
 		private var scanningForIFrame:Boolean = false; // When true, we are scanning video tags until we hit a keyframe/I-frame.
-		private var bufferParser:FLVParser = new FLVParser(false);
-
+		private var bufferParser:FLVParser = new FLVParser(false); // Used to parse incoming FLV stream to buffer. TODO: Refactor to be unnecessary.
+		private var needPendingSort:Boolean = false; // Set when we detect a new tag that's not after the last one, to save on resorts.
+		private var endAfterPending:Boolean = false;
+		
 		// Operations on buffer
 		/**
 			State/Logic

			// Feed Flash buffer if needed.
			keepBufferFed();
		}
		
		/**
		 * @private
		 * 

				appendBytes(buffer);
			}

			// Erase the consumed tags. Do it after to avoid costly array shifting.
			if(curTagOffset)
			{
				trace("Submitted " + curTagOffset + " tags, " + (pendingTags.length - curTagOffset) + " left");
				pendingTags.splice(0, curTagOffset);				
			}

			// If we're at the end of the stream, emit termination events.
			if(endAfterPending && pendingTags.length == 0)
			{
				trace("FIRING STREAM END");
				// For us, ending means ending the sequence, firing an onPlayStatus event,
				// and then really ending.	
				appendBytesAction(NetStreamAppendBytesAction.END_SEQUENCE);
				appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);

				var playCompleteInfo:Object = new Object();
				playCompleteInfo.code = NetStreamCodes.NETSTREAM_PLAY_COMPLETE;
				playCompleteInfo.level = "status";
				
				var playCompleteInfoSDOTag:FLVTagScriptDataObject = new FLVTagScriptDataObject();
				playCompleteInfoSDOTag.objects = ["onPlayStatus", playCompleteInfo];
				
				var tagBytes:ByteArray = new ByteArray();
				playCompleteInfoSDOTag.write(tagBytes);
				appendBytes(tagBytes);
				
				appendBytesAction(NetStreamAppendBytesAction.END_SEQUENCE);

				// And done ending.
				endAfterPending = false;
			}
		}

		public override function get bufferLength():Number
