refactoring for multiple ranges