refactored parseRanges into a utility that can be shared for both sides