             CGContextClearRect(ctx, ctxRect)
         }
 
-        var blockWidth = input.size.width / CGFloat(pixelGrid.width)
-        var blockHeight = input.size.height / CGFloat(pixelGrid.height)
+        let blockWidth = input.size.width / CGFloat(pixelGrid.width)
+        let blockHeight = input.size.height / CGFloat(pixelGrid.height)
         var attributes = [NSFontAttributeName: font, NSForegroundColorAttributeName: UIColor.blackColor()]
         for row in 0..<pixelGrid.height {
             for col in 0..<pixelGrid.width {
-                var block = pixelGrid.block(atRow: row, column: col)
-                var luminance = self.luminance(block)
-                var ASCIIResult = definition.stringForLuminance(Double(luminance))!
-                var rect = CGRect(x: blockWidth * CGFloat(col), y: blockHeight * CGFloat(row), width: blockWidth, height: blockHeight)
+                let block = pixelGrid.block(atRow: row, column: col)
+                let luminance = self.luminance(block)
+                let ASCIIResult = definition.stringForLuminance(Double(luminance))!
+                let rect = CGRect(x: blockWidth * CGFloat(col), y: blockHeight * CGFloat(row), width: blockWidth, height: blockHeight)
 
                 if colorMode == .Color {
                     let color = UIColor(red: CGFloat(block.r), green: CGFloat(block.g), blue: CGFloat(block.b), alpha: 1.0)

        if scaleFactor > min(image.size.height, image.size.width) {
            scaleFactor = min(image.size.height, image.size.width)
        }
        var ratio = scaleFactor / image.size.width
        var newWidth = scaleFactor
        var newHeight = ratio * image.size.height
        var size = CGSize(width: newWidth, height: newHeight)
        UIGraphicsBeginImageContextWithOptions(size, true, 1.0)
        image.drawInRect(CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
        var scaledImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return scaledImage
    }


    func convertImage(input: UIImage, completionHandler handler: ImageHandler) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
            let gridWidth = self.gridWidth(input.size.width)
            let output = self.convertImage(input, withFont: self.font, bgColor: self.backgroundColor, columns: gridWidth, reversed: self.reversedLuminance, colorMode: self.colorMode)
            dispatch_async(dispatch_get_main_queue()) { handler?(output) }
        }
    }

    func convertToString(input: UIImage, completionHandler handler: StringHandler) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
            let output = self.convertToString(input)
            dispatch_async(dispatch_get_main_queue(), { handler?(output) })
        })
    }

    func convertImage(input: UIImage) -> UIImage {
        let gridWidth = self.gridWidth(input.size.width)
        let output = convertImage(input, withFont: font, bgColor: backgroundColor, columns: gridWidth, reversed: reversedLuminance, colorMode: colorMode)
        return output
    }

    func convertImage(input: UIImage, withFont font: UIFont, bgColor: UIColor, columns: Int, reversed: Bool, colorMode: ColorMode) -> UIImage {
        let opaque = !isTransparent()
        _ = font.pointSize
        let gridWidth = columns
        let scaledImage = downscaleImage(input, withFactor: gridWidth)
        let pixelGrid = pixelGridForImage(scaledImage)
        UIGraphicsBeginImageContextWithOptions(input.size, false, 0.0)

        // Setup background
