Range map rework

Better RangeMap implementation with unit tests and smaller methods.