stage 7b query 3 not needed to run every loop, it is slow, so added check to only run sometimes