Fixed main loop to have state variables change in vertex only.