Reduce some duplication in range logic