update for new registry
simple optimization and bugfix
somewhat functional, SQL-based optimization for iterators