removed itertools reference because my implementation doesn't resemble that at all