alter bit of code to itertools for the win