Righteousness is NOT based on what you do, how you behave, or your actions and morality!!! Period!
Righteousness is a free gift by faith!! Not earned, or kept by some code of conduct.
Israel struggled with this forever (and still does) and the "church" has followed right in her footsteps, trying to earn or behave righteously apart from the free gift by faith.
Paul address this in Romans 9. Towards the end of the chapter he says, "The Gentiles, who did not PURSUE righteousness have attained it, that is, a righteousness that is by faith; but that Israel who PURSUED a law that would lead to righteousness did not succeed."
Here is how Paul describes the "why" of that in a translation journey:
"Because they did not pursue it by faith, but as if it were based on works." (ESV)
"Because their minds wre fixed on what they achieved instead of on what why believed." (Phillips)
""I have come to this conclusion. The non-Jews who had no relationship to God have received a right relationship to him through faith. But the Jews who looked for a right relationship by keeping the rules have failed to keep the rules. 'Why?' you ask. Because they tried to acheive it through their own eforts and not through faith." (Ben Campbell Johnson)
"Why, that the Gentiles, who never aimed at justifying themselves, attained justification, the justification which comes of faith; whereas the Israelites aimed at a disposition which should justify them, and never reached it. Why was this? Because they hoped to derive their justification from observance, not from faith." (Knox)
"That Gentiles, the ones who do not earnestly endeavor to acquire righteousness, appropriated righteousness, in fact, a righteousness which is out of a source of faith. But Israel, earnestly endeavoring to acquire a law of righteousness, did not measure up to the law. Because of what? Because, not out of a source of faith but even as out of a source of works they sought to acquire it." (Wuest)
"How can we sum this up? All those people who didn't seem interested in what God was doing actually embraced what God was doing as he straightened out their lives. And Israel, who seemed so interested in reading and talking about what God was doing, missed it. How could they miss it? Because instead of trusting God, they took over. They were absorbed in what they themselves were doing. They were so absorbed in their 'God projects' that they didn't notice God right in front of them, like a huge rock in the middle of the road." (Message) (emphais theirs)
So what is my conclusion? As long as one tries to attain righteousness, by works, actions, deeds, behavior, or tries to keep or maintain righteousness by any of the same, is doomed to miss the point all together and never actually enjoy the benefit of living righteously.
Righteousness is NOT something we earn or keep of our own. It is NOT something we owe back to God by our behavior. It is a gift of faith that we simply believe and appropriate. We live it.
Righteousness is the FRUIT of belief!! Not a manufactured system of behavior.
You are righteous because of Jesus Christ and His once and for all perfect sacrifice. "For he [God] hath made him [Jesus] to be sin for us, who knew no sin; that we [you and I and all humanity] might be made the righteousness of God in him." (2 Cor. 5:21 (KJV)
Notice the word "made". It is the Greek word "ginomai" and it means "to cause to be"; "to become, come into being". Realize that this is a work done TO you and not BY you. You have been made righteous apart from your doing, and in many cases, in spite of your own efforts.
So quit trying to produce righteousness and just be righteous, which will produce its own fruit naturally.
You are righteous. Believe it and live from it.