This, unless you really need a closure for a short function, but
Many event scripts have legacy scope rules that prevent def from pulling in any top level variables in that script into the function scope. Move such to project library scripts. (That's why you see import system in functions def'd in those scopes.)