refactoring the range.js file