better algorithm for huffman tree creation