Add utilities for repo iterators.
Split query functions to a separate file.
Refactor query functions.