fix bug in triangular matrices