Motive, motive, motive. Follow the motive. I believe people can do the right thing, for the wrong motive, and still be sinning. If their motive, is a just a way to get around something, they will not please God, no matter what they do.
It’s all in the heart which was the focus on the Beatitude Jesus taught on the Sermon on the Mount.
In Matthew 23 He shredded the pharisees for doing the right thing with the wrong heart motive.