Refactor: use list comprehensions and generators