simpler code, works if range is a single value