Convert a few loops to use ranges.