New implementation, based on generators.