Improve logic to avoid visiting synthetic nodes