Bug fix: wrong encoding/decoding of uint64.
Added more tests, fix comments, small bugs and typos.