         return roundImage
     }
 
+    struct BubbleMaskImage {
+
+        static let leftTail: UIImage = {
+            let scale = UIScreen.mainScreen().scale
+            let orientation: UIImageOrientation = .Up
+            var maskImage = UIImage(CGImage: UIImage(named: "left_tail_image_bubble")!.CGImage, scale: scale, orientation: orientation)!
+            maskImage = maskImage.resizableImageWithCapInsets(UIEdgeInsets(top: 25, left: 27, bottom: 20, right: 20), resizingMode: UIImageResizingMode.Stretch)
+            return maskImage
+            }()
+
+        static let rightTail: UIImage = {
+            let scale = UIScreen.mainScreen().scale
+            let orientation: UIImageOrientation = .UpMirrored
+            var maskImage = UIImage(CGImage: UIImage(named: "left_tail_image_bubble")!.CGImage, scale: scale, orientation: orientation)!
+            maskImage = maskImage.resizableImageWithCapInsets(UIEdgeInsets(top: 25, left: 27, bottom: 20, right: 20), resizingMode: UIImageResizingMode.Stretch)
+            return maskImage
+            }()
+    }
+
     func bubbleImageWithTailDirection(tailDirection: MessageImageTailDirection, size: CGSize) -> UIImage {
 
-        let scale = UIScreen.mainScreen().scale
         let orientation: UIImageOrientation = tailDirection == .Left ? .Up : .UpMirrored
-        var maskImage = UIImage(CGImage: UIImage(named: "left_tail_image_bubble")!.CGImage, scale: scale, orientation: orientation)!
-        maskImage = maskImage.resizableImageWithCapInsets(UIEdgeInsets(top: 25, left: 27, bottom: 20, right: 20), resizingMode: UIImageResizingMode.Stretch)
-        maskImage = maskImage.renderAtSize(size)
+
+        let maskImage: UIImage
+
+        if tailDirection == .Left {
+            maskImage = BubbleMaskImage.leftTail.renderAtSize(size)
+        } else {
+            maskImage = BubbleMaskImage.rightTail.renderAtSize(size)
+        }
 
         let bubbleImage = self.fixRotation().cropToAspectRatio(size.width / size.height).resizeToTargetSize(size).maskWithImage(maskImage)
 
         return bubbleImage
     }
 
-//    func maskWithImage(maskImage: UIImage) -> UIImage {
-//
-//        let scale = UIScreen.mainScreen().scale
-//
-//        let colorSpace = CGColorSpaceCreateDeviceRGB()
-//        let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
-//        let context = CGBitmapContextCreate(nil, Int(maskImage.size.width * scale), Int(maskImage.size.height * scale), 8, 0, colorSpace, bitmapInfo)
-//
-//        CGContextSetAllowsAntialiasing(context, true)
-//        CGContextSetShouldAntialias(context, true)
-//
-//        let drawRect = CGRect(origin: CGPointZero, size: self.size)
-//
-//        CGContextClipToMask(context, drawRect, maskImage.CGImage)
-//
-//        CGContextDrawImage(context, drawRect, self.CGImage)
-//
-//        let cgImage = CGBitmapContextCreateImage(context)!
-//        let roundImage = UIImage(CGImage: cgImage)!
-//
-//        return roundImage
-//    }
-}
+}

        return roundImage
    }

//    func bubbleImageWithTailDirection(tailDirection: MessageImageTailDirection, size: CGSize) -> UIImage {
//        let bubbleImage = self.fixRotation().cropToAspectRatio(size.width / size.height).resizeToTargetSize(size).bubbleImageWithTailDirection(tailDirection)
//
//        return bubbleImage
//    }
}

extension UIImage {

        transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(0.0, self.size.height))
        CGContextConcatCTM(context, transform)

        let drawRect = CGRect(origin: CGPointZero, size: self.size)

        CGContextClipToMask(context, drawRect, maskImage.CGImage)
