Fix encoding / decoding method

Use variable byte coding in case of a number which is longer than int.
Add comments