Fixed bug and reduced code

The current if-then-else statements only work with single byte characters. It should be fixed by now.

Also, the code was improved a little.