minor changes, some generators instead of list comprehension