Small refactor
Refactor range function