Replaced inner loop with a list comprehension.