some itertools magic