refactored `with_scope` into `Scoped`, making everything much less sketchy and adding docstrings