Add range calculation function