Refactoring and looping
better looping, test for loops, cloning, getState and stuff