adjust iteration to query according to mode; add error handling for data store