Improve scope filtering heuristic (#1077)

* Improve scope filtering heuristic

* fix tests
3 files changed