Update looping logic to be cleaner.