You've got it right.
Jesus KNEW who Judas Iscariot was and what he would do. I think that Judas was part of the template that Jesus showed us. HE chose 12 apostles and ONE was bad. That tells us that we will be finding our men of the cloth flawed sometimes.
Popes don't err when it comes to doctrine and morality. That is the Holy Spirit working. The other stuff? Well, that is humanity working.
My opinion.
Amen. No matter what they did as sinners, they did not corrupt God's teachings. David was no bargain either and Peter had his moments. God picked people to spread his message, warts and all.