Add docstring to createNodeIfNecessary