improved the code for huffmanencoder