Fix: Speed up getScope() (refs #1212)

Instead of reverse()ing, iterates parents backwards.
Indexes scopes for direct random lookup rather than linear search.
Merge pull request #1216 from btmills/faster-getscope

Fix: Speed up getScope() (refs #1212)