Make range selection code more universal