De-duplicate query method common loops.
Extract visit-all logic to a new method.