Changed loop to DRY proper loop