Iterators! Iterators everywhere!

It may seem that I rewrote the whole thing, but this is actually mostly re-organization. Functions have been moved, turned into methods (and thus indented), etc.

Also: enable some tests that were missing or commented.