fix bug in matrix