Bugfixes

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