Converted for loops to for comprehensions where appropriate.