     // MARK: Render
     
     // create a pipeline state descriptor for a vertex/fragment shader combo
-    func renderPipelineStateFor(label label:String!, fragmentShader:String!, vertexShader: String?) -> (MTLRenderPipelineState?, MTLRenderPipelineReflection?) {
-        
-        if  let shaderLibrary = _shaderLibrary,
+    func renderPipelineStateFor(label label:String, fragmentShader:String, vertexShader: String?) -> (MTLRenderPipelineState?, MTLRenderPipelineReflection?) {
+        
+        if  let device = device,
+            let shaderLibrary = _shaderLibrary,
             let fragmentProgram = shaderLibrary.newFunctionWithName(fragmentShader),
             let vertexProgram = shaderLibrary.newFunctionWithName(vertexShader ?? "defaultVertex") {
             

            destDescriptor = self._intermediateRenderPassDescriptor[self._currentDestTexture]
        }
        
        var blurTex = _rgbTexture
        
        if applyBlur && _currentVideoFilterUsesBlur, let args = _blurArgs {
            let parameters = [args.bufferAndOffsetForElement(_currentBlurBuffer)]
            createRenderPass(commandBuffer,
                             pipeline:  _blurPipelineStates[0],
                             vertexIndex: 0,
                             fragmentBuffers: parameters,
                             sourceTextures: [_rgbTexture],
                             descriptor: _intermediateRenderPassDescriptor[0],
                             viewport: nil)
            

            var y_texture: Unmanaged<CVMetalTexture>?
            let y_width = CVPixelBufferGetWidthOfPlane(pixelBuffer, 0)
            let y_height = CVPixelBufferGetHeightOfPlane(pixelBuffer, 0)
            CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, nil, MTLPixelFormat.R8Unorm, y_width, y_height, 0, &y_texture)
            
            var uv_texture: Unmanaged<CVMetalTexture>?
            let uv_width = CVPixelBufferGetWidthOfPlane(pixelBuffer, 1)
            let uv_height = CVPixelBufferGetHeightOfPlane(pixelBuffer, 1)
            CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, nil, MTLPixelFormat.RG8Unorm, uv_width, uv_height, 1, &uv_texture)
            
            guard let yTexture = y_texture, let uvTexture = uv_texture else {
                    return
            }
            
            let luma = CVMetalTextureGetTexture(yTexture.takeRetainedValue())!
            let chroma = CVMetalTextureGetTexture(uvTexture.takeRetainedValue())!
            
            let yuvTextures:[MTLTexture] = [ luma, chroma ]
            
            // create the YUV->RGB pass
            createRenderPass(commandBuffer,
                             pipeline: currentColorFilter,
                             vertexIndex: 0,
                             fragmentBuffers: [colorArgs.bufferAndOffsetForElement(_currentColorBuffer)],
                             sourceTextures: yuvTextures,
                             descriptor: rgbDescriptor,
                             viewport: nil)
            
            CVMetalTextureCacheFlush(textureCache, 0)
            
        }
    }
