Refactored some functions to work with list comprehensions