more robust encoding of non-ascii characters
allow custom reference codes