Different bug workaround. Now it is clear what happens.
Added comments
Merge pull request #10 from teodozjan/master

This seems nice and simple, and may be faster than the byte-by-byte workaround.