Duplicate frozen strings before forcing the encoding to prevent a RuntimeError

This is a fix for #375