Refactor loop to use all