using generators to deal with nested lists