The following helped me to understand what God is commanding when He asks us to have an upright intention, and an upright will. It is from St. Thomas Aquinas commenting on the commandments:
https://archive.org/details/AquinasOnTheCommandments/page/n81/mode/2up1. The heart: intention. You must know that the intention is understood by the heart. The intention has such power that it draws all works to itself. Hence actions that are good in themselves become bad by a bad intention. Our Lord says (St. Luke xi. 34), 'The light of thy body is thy eye. If thy eye be single, thy whole body will be lightsome; but if it be evil, thy body also will be darksome.' He means this: If your intention be bad, the whole gathering of your good works will become dark. Besides, in every work our intention must be fixed on God: as St. Paul says (1 Cor. x. 31), 'Whether you eat or drink, or whatsoever else you do, do all to the glory of God.’2. The soul: a good will. A good intention is not enough; there must be also a good will, which is signified by the soul. A man often acts fruitlessly, notwithstanding his good intention, from the want of a good will. Thus he might steal to feed a poor man. Here there is a good intention, but the needful uprightness of will is wanting. No wicked deed is excused by a good intention. This is the teaching of St. Paul, who says (Rom. iii. 8), 'And not rather, as we are slandered and as some affirm that we say, let us do evil that there may come good; whose damnation is just.' In truth, a good will is added to a good intention when the will is in agreement with the will of God. We daily pray for this, saying in our Lord's words (St. Matt, v. 10), 'Hallowed by Thy name. Thy kingdom come. Thy will be done on earth, as it is in Heaven.' So our Lord says in prophecy (Ps. xxxix. 8, 9), 'Behold I come: in the head of the book it is written of me that I should do Thy will: O my God, I have desired it; and Thy law is in the midst of my heart.' Because of these reasons Jesus says, 'With thy whole soul:' for in Scripture the soul is often taken for the will. Thus (Heb. x. 38), 'If he withdraw himself he shall not please My soul:’ that is to say, he will not be in union with God's will. Please, for the love of God, do not take this as an insult directed at you Mrs. Gray. I am sharing something that is related to the topic at hand for the benefit of those reading this. I underlined a part in the commentary that many people today, generally, do not understand.