         }
     }
     
+    func outputPathString() -> String {
+        if (outputPath != nil) {
+            return outputPath!
+        }
+        else {
+            return applicationDocumentsDirectory.absoluteString!
+        }
+    }
+    
     func createImageFromView(captureView : UIView) {
         UIGraphicsBeginImageContextWithOptions(captureView.bounds.size, false, 0)
         captureView.drawViewHierarchyInRect(captureView.bounds, afterScreenUpdates: false)
         
         let image = UIGraphicsGetImageFromCurrentImageContext();
-        let data = (outputJPG) ? UIImageJPEGRepresentation(image, 0) : UIImagePNGRepresentation(image)
+        
+        var fileExtension = "png"
+        var data : NSData?
+        if (outputJPG) {
+            data = UIImageJPEGRepresentation(image, 1)
+            fileExtension = "jpg"
+        }
+        else {
+            data = UIImagePNGRepresentation(image)
+        }
         
         imageCounter = imageCounter + 1
-        var path : NSString?
+        var path = outputPathString()
+        path = path.stringByAppendingPathComponent("/image\(imageCounter).\(fileExtension)")
         
-        if (outputPath != nil) {
-            path = outputPath
-        }
-        else {
-            path = applicationDocumentsDirectory.absoluteString!.stringByAppendingPathComponent("/image\(imageCounter).png")
-        }
-        
-        data.writeToURL(NSURL(string: path!)!, atomically: false)
+        data!.writeToURL(NSURL(string: path)!, atomically: false)
         
         UIGraphicsEndImageContext();
     }

        
        let seconds = referenceDate?.timeIntervalSinceNow
        if (seconds != nil) {
            println("Recorded \(imageCounter) images for a duration of \(-1 * seconds!) seconds, stored in: \(applicationDocumentsDirectory)")
        }
    }
    

    var view : UIView?
    var outputPath : NSString?
    var referenceDate : NSDate?
    var outputJPG = true
    
    func start() {
        
