Added fix and test to constrain the aggregate queries to the master id's passed in