fix use of itertools.cycle for python3
fix namespace error