Added unit tests and code clean up
Fixed the dependency on platform charset.
Just use a plain text string for charset name.