Code refactoring. Add utf8 encoding

done issue #318