Would it make sense to rename $data to $nodeName to make it easier to see whats going on?