Fixing problems with encode

Nice Plugin!
But I had problems with document encode, I did some changes, ok?