Check if node exists before trying to expand or collapse.