Keep doing good things, no matter your intention. When someone studies Torah with self-serving interests, that holy act becomes trapped within the kelipah. But this is only a temporary situation. Once a person returns to Hashem in teshuva, their previous acts of holiness are released and return with them. This is not just a possible outcome. It is a definite outcome! Every person will ultimately do teshuva, whether in this incarnation or another. And once that happens, all acts of holiness from all previous incarnations will be released and ascend to the holy sefirot. For this reason, our Sages said that a person should always engage in Torah study and performance of mitzvot, even if he does so not for their own sake. With regards to Torah and mitzvot done out of habit, teshuva is not needed to raise the acts of holiness to their place in the higher worlds because they were never trapped in the kelipah. All that is needed is to study the same subject again for the sake of Hashem, and that elevates the previous study as well. The same is true of prayer.