If an action may be good, but our intention is not fully pure, should we do the action anyway or refrain from it?

If the action is not haram, but the intention is not pure, you will not get thawab for doing it.