diff --git a/vp8/encoder/mbgraph.c b/vp8/encoder/mbgraph.c
index 4f9ba125bf8d2510adb723be8b13c59a25cd5b37..79b7fd595853a77ff8abb79f68bbcb67eb12b496 100644
--- a/vp8/encoder/mbgraph.c
+++ b/vp8/encoder/mbgraph.c
@@ -478,15 +478,19 @@ void separate_arf_mbs
     if ( 1 )
     {
         // Note % of blocks that are marked as static
-        cpi->static_mb_pct =
-            (ncnt[1] * 100) / cm->MBs;
+        if ( cm->MBs )
+            cpi->static_mb_pct = (ncnt[1] * 100) / cm->MBs;
+
+        // This error case should not be reachable as this function should
+        // never be called with the common data structure unititialized.
+        else
+            cpi->static_mb_pct = 0;
 
         vp8_enable_segmentation((VP8_PTR) cpi);
     }
     else
     {
         cpi->static_mb_pct = 0;
-
         vp8_disable_segmentation((VP8_PTR) cpi);
     }
 
diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index 25b56691d5fd14724743566bb72850a1e9886c89..6715ac2f61d11b131d8f44525dc4d8d84cc751d1 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -4554,6 +4554,9 @@ static void encode_frame_to_data_rate
             int high_err_target = cpi->ambient_err;
             int low_err_target = ((cpi->ambient_err * 3) >> 2);
 
+            // Prevent possible divide by zero error below for perfect KF
+            kf_err += (!kf_err);
+
             // The key frame is not good enough
             if ( (kf_err > high_err_target) &&
                  (cpi->projected_frame_size <= frame_over_shoot_limit) )