some refactoring for huffman encoder