changed itertools import to support python 2 and 3