added character encoding
removed globals