Factor loop closure into method to make scoping less onerous.