various issues related to encoding larger gaps than anticipated, mostly ...

...solved by moving to 64 bits calculations where required, clarifying signedness and adding asert to catch problems