function createNode( row ) {
          if ( !row.internalRow && row.treeLevel !== row.entity.$$treeLevel ) {
            row.treeLevel = row.entity.$$treeLevel;
          }

          if ( row.treeLevel <= currentLevel ) {
            // pop any levels that aren't parents of this level, formatting the aggregation at the same time
            while ( row.treeLevel <= currentLevel ) {
              var lastParent = parents.pop();
              service.finaliseAggregations( lastParent );
              currentLevel--;
            }

            // reset our current state based on the new parent, set to expanded if this is a level 0 node
            if ( parents.length > 0 ) {
              currentState = service.setCurrentState(parents);
            }
            else {
              currentState = uiGridTreeBaseConstants.EXPANDED;
            }
          }

          // If row header as parent exists in parentsCache
          if (
            typeof row.treeLevel !== 'undefined' &&
            row.treeLevel !== null &&
            row.treeLevel >= 0 &&
            parentsCache.hasOwnProperty(row.uid)
          ) {
            parents.push(parentsCache[row.uid]);
          }

          // aggregate if this is a leaf node
          if ( ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) && row.visible  ) {
            service.aggregate( grid, row, parents );
          }

          // add this node to the tree
          if (!parentsCache.hasOwnProperty(row.uid)) {
            service.addOrUseNode(grid, row, parents, aggregations);
          }

          if ( typeof(row.treeLevel) !== 'undefined' && row.treeLevel !== null && row.treeLevel >= 0 ) {
            if (!parentsCache.hasOwnProperty(row.uid)) {
              parentsCache[row.uid] = row;
              parents.push(row);
            }
            currentLevel++;
            currentState = service.setCurrentState(parents);
          }

          // update the tree number of levels, so we can set header width if we need to
          if ( grid.treeBase.numberLevels < row.treeLevel + 1) {
            grid.treeBase.numberLevels = row.treeLevel + 1;
          }
        }
@ngdoc function
@name createTree
@methodOf  ui.grid.treeBase.service:uiGridTreeBaseService
@description Creates a tree from the renderableRows

@param {Grid} grid The grid
@param {array} renderableRows The rows we want to create a tree from
@returns {object} The tree we've build