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

Instead of reverse()ing, iterates parents backwards.
Indexes scopes for direct random lookup rather than linear search.