replaced for loops with list slices