diff --git a/picture_colorbox.js b/picture_colorbox.js
index 219b2a1..38035bb 100644
--- a/picture_colorbox.js
+++ b/picture_colorbox.js
@@ -7,32 +7,40 @@
         if (href.search('#picture-colorbox-') === 0) {
           href = '.' + href.substr(1, href.length) + ', #' + href.substr(1, href.length);
         }
-        var $target = $(href);
-        $('span[lazyload]', $target).replaceWith(function () {
+
+        // Lazyload picture element when relevant.
+        $('span[lazyload]', $(href)).replaceWith(function () {
+          // Only execute if there are elements to process.
+          if (this.length == 0) {return;}
+
           var picture = $('<div>').append($(this).clone()).html();
 
           picture = picture.replace(/<span/ig, '<picture');
           picture = picture.replace(/<\/span>/ig, '</picture>');
           picture = picture.replace(/ data-srcset="/ig, ' srcset="');
-          $('img', picture).load(function() {
-            // Ensure there's no max-width / max-height otherwise we won't get
-            // the proper values. We could use naturalWeight / naturalHeight
-            // but that's not supported by <IE9 and Opera.
-            this.style.maxHeight = $(window).height() + 'px';
-            this.style.maxWidth = $(window).width() + 'px';
-            $.colorbox.resize({innerHeight: this.height, innerWidth: this.width});
-            // Remove overwrite of this values again to ensure we respect the
-            // stylesheet.
-            this.style.maxHeight = null;
-            this.style.maxWidth = null;
-
-            $.colorbox.resize();
-          });
 
           return $(picture).attr('lazyload', null);
         });
-      }).bind('cbox_complete', function () {
-        $.colorbox.resize();
+
+        $('picture img', $(href)).load(function() {
+          // Prevent images from being larger than the screen size.
+          var width = this.width;
+          var height = this.height;
+          var aspect = width / height;
+          var maxWidth = Math.floor($(window).width() * .9);
+          var maxHeight = Math.floor($(window).height() * .9);
+
+          if (width > maxWidth){
+            width = maxWidth;
+            height = Math.floor(width * aspect);
+          }
+          if (height > maxHeight) {
+            height = maxHeight;
+            width = Math.floor(height * aspect);
+          }
+
+          $.colorbox.resize({innerHeight: height, innerWidth: width});
+        });
       });
     }
   };
