diff --git a/src/modules/_Image_JPEG/module.pmod.in b/src/modules/_Image_JPEG/module.pmod.in
index 770cf6842a309478f5f2ac8b134fa97919800252..8f04c8c3f8faf1e1519e6f8298c2e1982aed1741 100644
--- a/src/modules/_Image_JPEG/module.pmod.in
+++ b/src/modules/_Image_JPEG/module.pmod.in
@@ -5,12 +5,9 @@
 
 inherit @module@;
 
-static object exif_flip_jpeg(object img, mapping exif)
+protected Image.Image exif_flip_jpeg(Image.Image img, mapping exif)
 {
-    if (!exif)
-	return img;
-
-    //Stdio.stderr->write("JPEG/EXIF: Orientation %O\n", exif->Orientation);
+    // FIXME: Can we use jpegtransform for any of this?
     switch (exif->Orientation)
     {
     case "1": /* default orientation */
@@ -51,54 +48,44 @@ static object exif_flip_jpeg(object img, mapping exif)
     return img;
 }
 
-object decode(string data, mapping|void options)
-{
-    //Stdio.stderr->write("Image.JPEG overloaded decode.\r\n\n");
-    object img = ::decode(data, options || ([ ]) );
-
-    if (!img) // early exit if error
-	return img;
-
-    mapping exif = Standards.EXIF.get_properties(Stdio.FakeFile(data));
-
-    return exif_flip_jpeg(img, exif);
-}
-
-mapping _decode(string data, mapping|void options)
+//! Decodes the image as @[_decode] would and then proceeds to decode
+//! any EXIF information in the image. If it contain any Orientation
+//! information the image will be flipped/rotated according to it. The
+//! EXIF data will be returned as a mapping under the key
+//! @expr{"exif"@}. If an error is encountered during the processing
+//! of EXIF information, the backtrace will be returned under the key
+//! @expr{"error"@}.
+mapping exif_decode(string data, mapping|void options)
 {
-    //Stdio.stderr->write("Image.JPEG overloaded _decode.\r\n\n");
     mapping m = ::_decode(data, options || ([ ]) );
 
     if (!m) // early exit if error
 	return m;
 
-    mapping exif = Standards.EXIF.get_properties(Stdio.FakeFile(data));
-
-    m->image = exif_flip_jpeg(m->image, exif);
-    if ((< "5", "6", "7", "8" >)[exif->Orientation])
-    {
-		/* If the image was flipped 90 or 270 degrees, we need to
-		 * exchange the x/y metadata information.
-		 */
-		m->xsize = m->image->xsize;
-		m->ysize = m->image->ysize;
-		int tmp = m->x_density;
-		m->x_density = m->y_density;
-		m->y_density = tmp;
-    }
+    mapping exif = ([]);
+    mixed err = catch {
+        exif = Standards.EXIF.get_properties(Stdio.FakeFile(data)) || ([]);
+
+        m->image = exif_flip_jpeg(m->image, exif);
+        if ((< "5", "6", "7", "8" >)[exif->Orientation])
+        {
+          /* If the image was flipped 90 or 270 degrees, we need to
+           * exchange the x/y metadata information.
+           */
+          m->xsize = m->image->xsize;
+          m->ysize = m->image->ysize;
+          int tmp = m->x_density;
+          m->x_density = m->y_density;
+          m->y_density = tmp;
+        }
+      };
+    if(err)
+      exif->error = err;
+    m->exif = exif;
 
     return m;
-}
 
-mapping raw_decode(string data, mapping|void options)
-{
-    // Compatibility function to bypass the overloading of _decode.
-
-    //Stdio.stderr->write("Image.JPEG overloaded _decode.\r\n\n");
-    return ::_decode(data, options || ([ ]) );
 }
-
-
 #else
 constant this_program_does_not_exist = 1;
 #endif // constant(@module@)