Merge pull request #12 from szabadka/master

Decoder code cleanup.
Fix potential output buffer overflow in encoder.