Removed function variables, switched to using nonlocal in closures