Refactor main tree walker in examples/sanitizer.lua into a function