protected BestMatchingCellAndSegment getBestMatchingCell(Column currentColumn, int time) {
    List<DistalDendriteSegment> bestMatchingSegmentsFromCells = new ArrayList<DistalDendriteSegment>();
    for (Cell cell : currentColumn.getElementsList()) {
      if (cell.getSegments().size() == 0) {
        break;
      }
    }
    Cell minSegmentListCell = currentColumn.getElementsList().get(0);
    for (Cell cell : currentColumn.getElementsList()) {
      //By Kirill
      //Avoid selecting learning cell as best matching to make sure we use next cell in column to help with temporal forking
      if (cell.getLearnState(time)) {
        //Shift minCell to next, since we exclude this one
        int nextInx = cell.getCellIndex() + 1;
        if (nextInx < currentColumn.getElementsList().size()) {
          minSegmentListCell = currentColumn.getElementByIndex(nextInx);
        } else if (getBestMatchingSegment(cell, time) == null) {
          //LOG.warn("Possible repeating pattern, please increase number of cells in column");
        }
        continue;
      }
      if (cell.getSegments().size() < minSegmentListCell.getSegments().size()) {
        minSegmentListCell = cell;
      }
      DistalDendriteSegment bestMatchingSegment = getBestMatchingSegment(cell, time);
      if (bestMatchingSegment != null) {
        bestMatchingSegmentsFromCells.add(bestMatchingSegment);
      }
    }
    DistalDendriteSegment columnBestMatchingSegment = getBestMatchingSegment(bestMatchingSegmentsFromCells,
                                                                             time);

    return new WhitePaperTemporalPooler.BestMatchingCellAndSegment(
            columnBestMatchingSegment != null ? columnBestMatchingSegment.getOwner() : minSegmentListCell,
            columnBestMatchingSegment);
  }