Fix underflow in huffman encoding