Refactor checking for safe output into a separate node visitor.