added support for custom encoding