Refactored scope-related functions outside of core template view fork code