improve triangular code to finish version