fix bug when using custom encoding