ENH: add chainmap for easier scoping
CLN: move scoping code to its own module
ENH: catch key error for chainmap lookups