refactor ranging