minor refactoring
range rewritten tail-recursively
a lot of simplifications in the core
core simplification & extension