Simply/Consolidate logic in a loop to make the code easier to read