Reworked based on feedback from github.com/diffsky

Exporting functions directly, named anonymous function in limited --
means a new scope is not created every time.