But the LORD said unto Samuel, Look not on his countenance, or on the height of his stature; because I have refused him: for the LORD seeth not as man seeth; for man looketh on the outward appearance, but the LORD looketh on the heart. — 1 Samuel 16:7
God is the God of hearts. He does not look only at the exterior of a person, or even the things a person does, and judge the individual by that criterion. Man judges the flesh, but God judges the heart.
It is possible to do good works and still have a wrong heart attitude.
It is also possible to do some things wrong but still have a right heart on the inside.
God is much more inclined to use a person with a good heart and a few problems than He is to use a person who seems to have it all together but who has a wicked heart.
It is very important that we get in touch with our inner life and our heart attitude, the way we feel and think about things (what the Bible calls the hidden man of the heart), if we want to hear from God and live in close relationship with Him.
When God seeks to promote someone, He chooses a person after His own heart.