Scope inheritance reimplemented from scratch (clean)