modification to huffman
it works well but needs optimisations