small encode optimizations