Fix bug where string to be encoded is frozen