public Tree<String> buildTree(List<String> sentence, int i, int j, int parent, int[][][][] back){
		int leftChildIndex = back[i][j][parent][1];
//		System.out.println("parent: " + indexer.get(parent));
//		System.out.println("leftChild: " + indexer.get(leftChildIndex));
//		System.out.println("rightChild: " + indexer.get(backTrack[i][j][parent][2]));
//		System.out.println("------------------------------------");
//		if (leftChildIndex == 0){
//			return new Tree<String>(indexer.get(parent), Collections.singletonList(new Tree<String>(sentence.get(leftChildIndex))));
//		}
//		if (leftChildIndex != 0){
			if (parent == rootIndex && leftChildIndex == 0){
				return new Tree<String> (indexer.get(parent));
			}
			if (i==j-1){ // the bottom of DP table;
//				if (uc.getClosedUnaryRulesByParent(indexer.get(parent)).size() == 0){
				if (leftChildIndex == 0){
						return new Tree<String>(indexer.get(parent), Collections.singletonList(new Tree<String>(sentence.get(i))));
					} else {
						List<String> path = uc.getPath(new UnaryRule(indexer.get(parent),indexer.get(leftChildIndex)));
						List<Tree<String>> emptyList = Collections.emptyList();
						Tree<String> leaf = new Tree<String>(sentence.get(i), emptyList);
						return buildUnaryTree(path, Collections.singletonList(leaf));
					}
			}
//		}
			// for unary rule
//			try{
				if (back[i][j][parent][0] == 0){
					Tree<String> leaves = buildTree(sentence, i, j, leftChildIndex, back);
					UnaryRule unaryRule = new UnaryRule(indexer.get(parent), indexer.get(leftChildIndex));
					List<String> path = uc.getPath(unaryRule);
					Tree<String> unaryTree = buildUnaryTree(path.subList(0, path.size() - 1), Collections.singletonList(leaves));
					return unaryTree;
				}
//			} catch (ArrayIndexOutOfBoundsException e){
////				System.out.format("i: %d, j: %d, parent: %d", i, j, parent);
//				throw e;
//			}
//			}
			
			// for binary rule
			Tree<String> leftTree = buildTree(sentence, i, back[i][j][parent][0], leftChildIndex, back);
			Tree<String> rightTree = buildTree(sentence, back[i][j][parent][0], j, back[i][j][parent][2], back);
			List<Tree<String>> childrenList = new ArrayList<Tree<String>>(2);
			childrenList.add(leftTree);
			childrenList.add(rightTree);
			return new Tree<String>(indexer.get(parent), childrenList);

	}