Enhanced to support negative values for ranges.