Improved invalid char removal.