Bugfixes

I stumbled upon some error while developing on the huffman branch. It turned out that the errors was not because of any modifications I've made, but bugs already present. I wonder why they have turned up before.