broken state, but kind of works. speed improvement of 30 percent per iteration