performance improvements for encoding