factored out iterators to clozen, added some debugging, added a primitive apply function