Extracted scoping into its own module. Fixes #44