Refactored range access:

Added helper function for accessing range from range list, given index,
and refactored code to use it.