Code rewrites, add iteration and other fixes.