Fix range caliculation bug