refactoring and error correction charset