Added function, called rangeofN. Stops at appropriate value