I'm about to change the implementation here and I'd like to add some doctests, which means this needs to not be hidden inside another function.