some code for querying and scanning data