If you commit a mistake, don't get sad. Get happy for having a great opportunity to reflect on it and being able to improve yourself. Purification will not come by itself.
Majjhima Nikāya 61 wrote:"Rahula, all those brahmans & contemplatives in the course of the past who purified their bodily actions, verbal actions, & mental actions, did it through repeated reflection on their bodily actions, verbal actions, & mental actions in just this way.
"All those brahmans & contemplatives in the course of the future who will purify their bodily actions, verbal actions, & mental actions, will do it through repeated reflection on their bodily actions, verbal actions, & mental actions in just this way.
"All those brahmans & contemplatives at present who purify their bodily actions, verbal actions, & mental actions, do it through repeated reflection on their bodily actions, verbal actions, & mental actions in just this way.
"Thus, Rahula, you should train yourself: 'I will purify my bodily actions through repeated reflection. I will purify my verbal actions through repeated reflection. I will purify my mental actions through repeated reflection.' That's how you should train yourself."
Reflect before acting and after acting. If it brings suffering to you or to others, don't do it. If it brought suffering to you or to others, recognize the mistake and promise to restrain yourself in the future. Be equanimous, lamentation will do no help.
"Whenever you want to do a verbal action, you should reflect on it: 'This verbal action I want to do — would it lead to self-affliction, to the affliction of others, or to both? Would it be an unskillful verbal action, with painful consequences, painful results?'
"Having done a verbal action, you should reflect on it: 'This verbal action I have done — did it lead to self-affliction, to the affliction of others, or to both? Was it an unskillful verbal action, with painful consequences, painful results?'
Eyes downcast, not footloose,
senses guarded, with protected mind,
not oozing — not burning — with lust,
wander alone
like a rhinoceros.
Sutta Nipāta 1.3 - Khaggavisana Sutta
See, Ānanda! All those conditioned phenomena have passed, ceased, and perished. So impermanent are conditions, so unstable are conditions, so unreliable are conditions. This is quite enough for you to become disillusioned, dispassionate, and freed regarding all conditions.
Dīgha Nikāya 17