replaced for loops with extend