cleaned up code using list comprehensions