simplified, iteration

i sought some help on Stack Overflow on how to iterate through, instead
of having two identical blocks of code (identical except for the pull
left or pull right). Also simplified variables, classes, calls, etc.