logic for branching OR queries