Abstract text cleaning logic.