Switch algorithm for scope matching.

Switch algorithm for scope matching. Detailed in: Frameworks/scope/doc/design.md