General text refactoring