             }
 
             if (_pts_loading_in_progress == false) {
-                if (last_seqnum == _levels[_level].end_seqnum) {
+                if (last_seqnum == _levels[level].end_seqnum) {
                     // if last segment was last fragment of VOD playlist, notify last fragment loaded event, and return
                     if (_hls.type == HLSTypes.VOD) {
                         _hls.dispatchEvent(new HLSEvent(HLSEvent.LAST_VOD_FRAGMENT_LOADED));

            var log_prefix : String;
            var frag : Fragment;

            if (_switchlevel == false || _frag_previous.continuity == -1) {
                last_seqnum = _seqnum;
            } else {
                // level switch
                // trust program-time : if program-time defined in previous loaded fragment, try to find seqnum matching program-time in new level.
                if (_frag_previous.program_date) {
                    last_seqnum = _levels[_level].getSeqNumFromProgramDate(_frag_previous.program_date);
                    CONFIG::LOGGING {
                        Log.debug("loadnextfragment : getSeqNumFromProgramDate(level,date,cc:" + _level + "," + _frag_previous.program_date + ")=" + last_seqnum);
                    }
                }
                if (last_seqnum == -1) {
                    // if we are here, it means that no program date info is available in the playlist. try to get last seqnum position from PTS + continuity counter
                    last_seqnum = _levels[_level].getSeqNumNearestPTS(_frag_previous.data.pts_start, _frag_previous.continuity);
                    CONFIG::LOGGING {
                        Log.debug("loadnextfragment : getSeqNumNearestPTS(level,pts,cc:" + _level + "," + _frag_previous.data.pts_start + "," + _frag_previous.continuity + ")=" + last_seqnum);
                    }
                    if (last_seqnum == Number.POSITIVE_INFINITY) {
                        /* requested PTS above max PTS of this level:

            }
        };

        private function _loadfirstfragment(position : Number, level : int) : int {
            CONFIG::LOGGING {
                Log.debug("loadfirstfragment(" + position + ")");
            }
            // check if we received playlist for new level. if live playlist, ensure that new playlist has been refreshed
            if ((_levels[level].fragments.length == 0) || (_hls.type == HLSTypes.LIVE && _last_updated_level != level)) {
                // playlist not yet received
                CONFIG::LOGGING {
                    Log.debug("loadfirstfragment : playlist not received for level:" + level);
                }
                return 1;
            }
