Completed logic for createNode().