Factor out _checkScope from query and queryAll methods