              assetsWithVideoTracks: movieAssets)
 
 // Create the passthru and transition time ranges.
-let timeRanges = calculateTimeRanges(transitionDuration: transDuration,
-                                  assetsWithVideoTracks: movieAssets)
+// let timeRanges = calculateTimeRanges(transitionDuration: transDuration,
+//                                  assetsWithVideoTracks: movieAssets)
+
+let timeRanges = calculateTimeRanges(
+    transitionDuration: transDuration, assetsWithVideoTracks: movieAssets)
 
 // Create the instructions for which movie to show and create the video composition.
 let videoComposition = buildVideoCompositionAndInstructions(

    let videoComposition = AVMutableVideoComposition(propertiesOfAsset: composition)
                            
    // Now create the instructions from the various time ranges.
    for (var i = 0 ; i < passThroughTimeRanges.count ; ++i)
    {
        let trackIndex = i % 2
        let currentTrack = tracks[trackIndex]
        let instruction = AVMutableVideoCompositionInstruction()
        instruction.timeRange = passThroughTimeRanges[i].CMTimeRangeValue
        
        let layerInstruction = AVMutableVideoCompositionLayerInstruction(
                                                    assetTrack: currentTrack)
        instruction.layerInstructions = [layerInstruction]
        compositionInstructions.append(instruction)
        
        if i < transitionTimeRanges.count {
            let instruction = AVMutableVideoCompositionInstruction()
            instruction.timeRange = transitionTimeRanges[i].CMTimeRangeValue
            
            // Determine the foreground and background tracks.
            let fgTrack = tracks[trackIndex]
            let bgTrack = tracks[1 - trackIndex]

            // Create the "from layer" instruction.
            let fLInstruction = AVMutableVideoCompositionLayerInstruction(
                                                        assetTrack: fgTrack)
            
            // Make the opacity ramp and apply it to the from layer instruction.
            fLInstruction.setOpacityRampFromStartOpacity(1.0, toEndOpacity:0.0,
                                            timeRange: instruction.timeRange)

            // Create the "to layer" instruction. Do I need this?
            let tLInstruction = AVMutableVideoCompositionLayerInstruction(
                                                        assetTrack: bgTrack)
            instruction.layerInstructions = [fLInstruction, tLInstruction]
            compositionInstructions.append(instruction)
        }
    }
    videoComposition.instructions = compositionInstructions
    videoComposition.renderSize = renderSize
    videoComposition.frameDuration = CMTimeMake(1, 30)

    var passThroughTimeRanges:[NSValue] = [NSValue]()
    var transitionTimeRanges:[NSValue] = [NSValue]()
    var cursorTime = kCMTimeZero
    
    for (index, videoAsset) in enumerate(assetsWithVideoTracks) {
        var timeRange = CMTimeRangeMake(cursorTime, videoAsset.duration)
        if index > 0 {
            timeRange.start = CMTimeAdd(timeRange.start, transDuration)
            timeRange.duration = CMTimeSubtract(timeRange.duration, transDuration)
        }
        
        if index + 1 < assetsWithVideoTracks.count {
            timeRange.duration = CMTimeSubtract(timeRange.duration, transDuration)
        }
        
        passThroughTimeRanges.append(NSValue(CMTimeRange: timeRange))
        cursorTime = CMTimeAdd(cursorTime, videoAsset.duration)
        cursorTime = CMTimeSubtract(cursorTime, transDuration)
        
        if index + 1 < assetsWithVideoTracks.count {
            timeRange = CMTimeRangeMake(cursorTime, transDuration)
            transitionTimeRanges.append(NSValue(CMTimeRange: timeRange))
        }
    }

    return (passThroughTimeRanges, transitionTimeRanges)
}

