diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c
index ba0fea22c4f674768241ace315d3adcb742b83e9..84fc18779e8b45468b572896160bd7d76b8466fb 100644
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -2114,6 +2114,8 @@ void vp9_get_second_pass_params(VP9_COMP *cpi) {
     // Define next KF group and assign bits to it
     this_frame_copy = this_frame;
     find_next_key_frame(cpi, &this_frame_copy);
+  } else {
+    cpi->common.frame_type = INTER_FRAME;
   }
 
   // Is this a GF / ARF (Note that a KF is always also a GF)
diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c
index 2e34b4a786f36e2e820205c7bf5e017abe30adbc..95610476de7ce7e3c315eb68665dd672a28c7db9 100644
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -2913,19 +2913,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
   // Current default encoder behavior for the altref sign bias.
   cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = cpi->rc.source_alt_ref_active;
 
-  // Check to see if a key frame is signaled.
-  // For two pass with auto key frame enabled cm->frame_type may already be
-  // set, but not for one pass.
-  if ((cm->current_video_frame == 0) ||
-      (cm->frame_flags & FRAMEFLAGS_KEY) ||
-      (cpi->oxcf.auto_key && (cpi->rc.frames_since_key %
-                              cpi->key_frame_frequency == 0))) {
-    // Set frame type to key frame for the force key frame, if we exceed the
-    // maximum distance in an automatic keyframe selection or for the first
-    // frame.
-    cm->frame_type = KEY_FRAME;
-  }
-
   // Set default state for segment based loop filter update flags.
   cm->lf.mode_ref_delta_update = 0;
 
@@ -3165,7 +3152,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
 #endif
 
     // As this frame is a key frame the next defaults to an inter frame.
-    cm->frame_type = INTER_FRAME;
     vp9_clear_system_state();
     cpi->rc.frames_since_key = 0;
   } else {
diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c
index 8a0dd4ceea1553073688115249d98d6c6843cc8a..bae87b71456d4fe0a23c24e05fbd1e659ef9a81b 100644
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -750,7 +750,6 @@ int vp9_rc_pick_q_and_adjust_q_bounds(const VP9_COMP *cpi,
   // Limit Q range for the adaptive loop.
   if (cm->frame_type == KEY_FRAME && !cpi->rc.this_key_frame_forced) {
     if (!(cpi->pass == 0 && cpi->common.current_video_frame == 0)) {
-      *top_index = active_worst_quality;
       *top_index =
           (active_worst_quality + active_best_quality * 3) / 4;
     }
@@ -790,6 +789,12 @@ int vp9_rc_pick_q_and_adjust_q_bounds(const VP9_COMP *cpi,
     printf("frame:%d q:%d\n", cm->current_video_frame, q);
   }
 #endif
+  assert(*top_index <= cpi->rc.worst_quality &&
+         *top_index >= cpi->rc.best_quality);
+  assert(*bottom_index <= cpi->rc.worst_quality &&
+         *bottom_index >= cpi->rc.best_quality);
+  assert(q <= cpi->rc.worst_quality &&
+         q >= cpi->rc.best_quality);
   return q;
 }