Working code to extract triangular matrix.