Fixed cutAndGetResidue fuction and huffman encode funcrion