correction to the index in keep_frames function