A nicer approach with less binary searches.