typo in $nodeId variable name and fixed variable scope