Refactor out loop

Makes it clearer what I want to do there